Presentation is loading. Please wait.

Presentation is loading. Please wait.

MIDPOINT CIRCLE & ELLIPSE GENERARTING ALGORITHMS

Similar presentations


Presentation on theme: "MIDPOINT CIRCLE & ELLIPSE GENERARTING ALGORITHMS"— Presentation transcript:

1 MIDPOINT CIRCLE & ELLIPSE GENERARTING ALGORITHMS
Circle Generating Algorithm Properties of circle Midpoint circle algorithm Ellipse-generating algorithm Properties of ellipse Midpoint ellipse algorithm VITS CSE

2 Circle Generating Algorithm
Properties of Circle Circle is defined as the set of points that are all at a given distance r from a center point (xc,yc) For any circle point (x,y), the distance relationship is expressed by the Pythagorean theorem in Cartesian coordinate as: r yc ө (x,y) xc VITS CSE

3 Circle Generating Algorithm
We could use this equation to calculate the points on a circle circumference by stepping along x-axis in unit steps from xc–r to xc+r and calculate the corresponding y values as VITS CSE

4 Circle Generating Algorithm
The problems: Involves many computation at each stepi.e., square root and additions /subtractions Spacing between plotted pixel positions is not uniform Adjustment: interchanging x & y (step through y values and calculate x values) Involves many computation too! VITS CSE

5 Circle Generating Algorithm
Another way: Calculate points along a circular boundary using polar coordinates r and ө x = xc + r cos ө y = yc + r sin ө Using fixed angular step size, a circle is plotted with equally spaced points along the circumference Problem: trigonometric calculations are still time consuming VITS CSE

6 Symmetry of Circles (8-way symmetry)
Proposed Approach:symmetry of circles Shape of the circle is similar in each quadrant i.e. if we determine the curve positions in the 1st quadrant, we can generate the circle section in the 2nd quadrant of the xy plane (the 2 circle sections are symmetric with respect to the y axis) The circle section in the 3rd and 4th quadrant can be obtained by considering symmetry about the x axis One step further  symmetry between octants VITS CSE

7 8-way symmetry Circle sections in adjacent octants within 1 quadrant are symmetric with respect to the 45° line dividing the 2 octants Calculation of a circle point (x, y) in 1 octant yields the circle points for the other 7 octants 450 (y,x) (-y,x) (x,y) (x,-y) (y,-x) (-y,-x) (-x,-y) (-x,y) VITS CSE

8 Midpoint Circle Algorithm
As in raster algorithm, we sample at unit intervals & determine the closest pixel position to the specified circle path at each step For a given radius, r and screen center position (xc,yc) , we can set up our algorithm to calculate pixel positions around a circle path centered at the coordinate origin (0,0) Each calculated position (x, y) is moved to its proper screen position by adding xc to x and yc to y VITS CSE

9 Midpoint Circle Algorithm
Along a circle section from x=0 to x=y in the 1st quadrant, the slope (m) of the curve varies from 0 to -1.0 i.e. we can take unit steps in the +ve x direction over the octant & use decision parameter to determine which 2 possible positions is vertically closer to the circle path Positions in the other 7 octants are obtained by symmetry VITS CSE

10 Midpoint Circle Algorithm
To apply the midpoint method, we define a circle function as fcirc(x,y) = x2 + y2 - r2 The relative positions of any point (x,y) can be determined by checking the sign of the circle function: < 0, if (x,y) is inside the circle boundary fcirc(x,y) = 0, if (x,y) is on the circle boundary > 0, if (x,y) is outside the circle boundary VITS CSE

11 Midpoint Circle Algorithm
Consider current position (xk, yk) next pixel position is either(xk+1, yk) or (xk+1, yk-1)? xk yk xk+1 xk+2 yk-1 Circle path Midpoint VITS CSE

12 Midpoint Circle Algorithm
Our decision parameter is the earlier circle function evaluated at the mid point between the 2 pixels < 0: midpoint is inside the circle; plot (xk+1, yk) +ve: midpoint is outside the circle; plot (xk+1, yk-1) Successive decision parameters are obtained using incremental calculation pk VITS CSE

13 Midpoint Circle Algorithm
To ensure things are as efficient as possible we can do all of our calculations incrementally First consider: or where yk+1 is either yk or yk-1 depending on the sign of pk VITS CSE

14 Midpoint Circle Algorithm
Initial decision parameter is obtained by evaluating the circle function at the start position (x0, y0) = (0,r) p0 = f(1, r–1/2) = 12 + (r – 1/2)2 – r2 p0 = 5/4 – r If the radius is specified as an integer, we can simple round p0 to p0 = 1 – r Then if pk < 0 then the next decision variable is given as: If pk > 0 then the decision variable is: VITS CSE

15 Midpoint Circle Algorithm
Input radius, r, and circle center (xc, yc), then set the coordinates for the 1st point on the circumference of a circle centered at the origin as (x0, y0) = (0,r) Calculate initial value of decision parameter: At each xk, starting at k = 0, test the value of pk : If pk < 0, next point will be (xk+1, yk) and else, next point will be (xk+1, yk – 1) and where 2xk+1 = 2xk and 2yk+1 = 2yk – 2 Determine symmetry points in the other 7 octants. Get the actual point for circle centered at (xc,yc) that is (x+xc, y+yc). Repeat step 3 to 5 until x  y. VITS CSE

16 Try this out! Given a circle radius r=10, demonstrate the midpoint circle algorithm by determining positions along the circle octant in the 1st quadrant p0 = ? (x0,y0) = ? k pk (xk+1,yk+1) 2xk+1 2yk+1 1 2 3 4 5 6 VITS CSE

17 Plot pixel positions 10 9 8 7 6 5 4 3 2 1 VITS CSE

18 Try this again! Given a circle with r=8, calculate each pixel positions along the circumference at the 2nd quadrant VITS CSE

19 Ellipse Generating Algorithm
Ellipse – an elongated circle. A modified circle whose radius varies from a maximum value in one direction to a minimum value in the perpendicular direction. A precise definition in terms of distance from any point on the ellipse to two fixed position, called the foci of the ellipse. The sum of these two distances is the same value for all points on the ellipse. P=(x,y) F2 F1 d2 d1 VITS CSE

20 Ellipse Generating Algorithm
If the distance of the two focus positions from any point P=(x, y) on the ellipse are labeled d1 and d2, the general equation of an ellipse: d1 + d2 = constant Expressing distance d1 and d2 in terms of the focal coordinates F1=(x1, y1) and F2=(x2, y2), we have VITS CSE

21 Ellipse Generating Algorithm
However, we will only consider ‘standard’ ellipse: ry xc rx yc VITS CSE

22 2-way symmetry An ellipse only has a 2-way symmetry. (x,y) (-x,y) ry
rx ry VITS CSE

23 Equation of an ellipse Consider an ellipse centered at the origin, (xc,yc)=(0,0): Ellipse function …and its properties: fellipse(x,y) < 0 if (x,y) is inside the ellipse fellipse(x,y) = 0 if (x,y) is on the ellipse fellipse(x,y) > 0 if (x,y) is outside the ellipse VITS CSE

24 Midpoint Ellipse Algorithm
Ellipse is different from circle. Similar approach with circle, different in sampling direction. Slope of ellipse is: dy/dx = - 2ry2x/2rx2y Region 1: Sampling is at x direction Choose between (xk+1, yk), or (xk+1, yk-1) Move of region 1 if 2r2yx >= 2r2xy Region 2: Sampling is at y direction Choose between (xk, yk-1), or (xk+1, yk-1) Slope = -1 Region 1 Region 2 ry rx VITS CSE

25 Decision parameters Region 1: Decision parameter p1k < 0:
midpoint is inside choose pixel (xk+1, yk) p1k >= 0: midpoint is outside/on choose pixel (xk+1, yk-1) Region 2: Decision parameter p2k <= 0: midpoint is inside/on choose pixel (xk+1, yk-1) p2k > 0: midpoint is outside choose pixel (xk, yk-1) VITS CSE

26 Midpoint Ellipse Algorithm
Input rx, ry and ellipse center (xc, yc). Obtain the first point on an ellipse centered on the origin (x0, y0) = (0, ry). Calculate initial value for decision parameter in region 1 as: At each xk in region 1, starting from k = 0, test p1k :   If p1k < 0, next point (xk+1, yk) and else, next point (xk+1, yk-1) and   with 2ry2xk+1 = 2ry2xk + 2ry2, 2rx2yk+1 = 2rx2yk – 2rx2 and repeat step 1 to 3 until 2ry2x  2rx2y VITS CSE

27 Midpoint Ellipse Algorithm
Initial value for decision parameter in region 2: where (x0, y0) is the last position calculate in region 1 5. At each yk in region 2, starting from k = 0, test p2k:   If p2k > 0, next point is (xk, yk-1) and else, next point is (xk+1, yk-1) and continue until y=0 VITS CSE

28 Midpoint Ellipse Algorithm
For both region determine symmetry points in the other 3 quadrants Move each calculated pixel position (x,y) onto the elliptical path centered on (xc,yc) and plot the coordinate values x=x + xc, y =y + yc VITS CSE

29 Try this out! k p1k (xk+1,yk+1) 2ry2 xk+1 2 rx2yk+1 -332 (1,6) 72 768 1 -224 (2,6) 144 2 -44 (3,6) 216 3 208 (4,5) 288 640 4 -108 (5,5) 360 5 (6,4) 432 52 6 244 (7,3) 504 384 Given input ellipse parameter rx=8 and ry=6, determine pixel positions along the ellipse path in the first quadrant using the midpoint ellipse algorithm 2ry2x = ? 2rx2y = 2rx2ry = ? p10 = ? We now move out from R1 since2ry2 x> 2 rx2y For R2,initial point is(xo,yo)=(7,3)& p2o=f(7+1/2,2)=-151 k p2k (xk+1,yk+1) 2rv2 xk+1 2 rx2yk+1 -151 (8,2) 576 256 1 233 (8,1) 128 2 745 (8,0) -- VITS CSE

30 Plot pixel positions 6 5 4 3 2 1 7 8 VITS CSE


Download ppt "MIDPOINT CIRCLE & ELLIPSE GENERARTING ALGORITHMS"

Similar presentations


Ads by Google