Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 05: Mid-point Ellipse algorithm Dr. Manal Helal – Fall 2014

Similar presentations


Presentation on theme: "Lecture 05: Mid-point Ellipse algorithm Dr. Manal Helal – Fall 2014"— Presentation transcript:

1 Lecture 05: Mid-point Ellipse algorithm Dr. Manal Helal – Fall 2014
Computer Graphics CC416 Lecture 05: Mid-point Ellipse algorithm Dr. Manal Helal – Fall 2014

2 Ellipse Generation Algorithm
An ellipse is an elongated circle Therefore, elliptical curves can be generated by modifying circle-drawing procedures to take into account the different dimensions of an ellipse along the major and minor axes CC416 Computer Graphics

3 Start with the basic equation of a circle
Divide both sides by r2 The general equation of an ellipse can be stated as rx ry xc yc (x,y) CC416 Computer Graphics

4 Properties of Ellipses
An ellipse is defined as the set of points such that the sum of the distances from two fixed positions (foci) is the same for all points d1 d2 CC416 Computer Graphics

5 So Expressing distances d1, and d2, in terms of the focal coordinates F1 = (x1, y1) and F2 = (x2, y2), we have d1 d2 CC416 Computer Graphics

6 Symmetry considerations can be used to further reduce computations.
An ellipse in standard position is symmetric between quadrants, but unlike a circle, it is not symmetric between the two octants of a quadrant. Thus, we must calculate pixel positions along the elliptical arc throughout one quadrant, then we obtain positions in the remaining three quadrants by symmetry CC416 Computer Graphics

7 Mid-Point Ellipse Algorithm
The approach is similar to that used in displaying a circle Given parameters rx, ry, and (xc, yc), we determine points (x, y) for an ellipse in standard position centered on the origin Then the points are shifted so the ellipse is centered at (xc, yc) CC416 Computer Graphics

8 This is done according to the slope of the tangent
The mid-point ellipse method is applied throughout the first quadrant in two parts This is done according to the slope of the tangent When slope < -1, take unit steps in the x direction When slope > -1, take unit steps in the y direction CC416 Computer Graphics

9 the decision parameter will be according to
From equation When (xc, yc) = (0,0) the decision parameter will be according to CC416 Computer Graphics

10 So, the next pixel along the ellipse path according to the sign of the ellipse function evaluated at the midpoint between the two candidate pixels CC416 Computer Graphics

11 Starting at (0,ry) take unit steps in the x direction until reaching the boundary between region 1 and region 2 switch to unit steps in the y direction over the remainder of the curve in the first quadrant At each step, test the value of the slope using CC416 Computer Graphics

12 At the boundary between region 1 and region 2, dy/dx = - 1 and
Therefore, we move out of region 1 whenever CC416 Computer Graphics

13 Assuming position (xk, yk) has been selected at the previous step
Recall Assuming position (xk, yk) has been selected at the previous step the next position along the ellipse path is determined by evaluating the decision parameter CC416 Computer Graphics

14 If p1k < 0, the midpoint is inside the ellipse and the pixel on scan line y, is closer to the ellipse boundary. Otherwise, the mid position is outside or on the ellipse boundary, and we select the pixel on scan line yk - 1. CC416 Computer Graphics

15 where yk+1 is either yk or yk - 1, depending on the sign of p1k
At the next sampling position (xk+1+1 = xk + 2), the decision parameter for region 1 is evaluated as [(xk+1) + 1]2 = (xk+1)2 + 2(xk+1) + 1 [(Yk+1-(1/2))]2 = Yk+12 - Yk+1 + (1/4) P1k+1 = ry2(xk+1)2 + 2ry2 (xk+1) + ry2 +(rx2 Yk+12 - rx2Yk+1 + rx2 (1/4)) - rx2ry2 where yk+1 is either yk or yk - 1, depending on the sign of p1k P1k CC416 Computer Graphics

16 So decision parameters are incremented by the following amounts:
CC416 Computer Graphics

17 In region 1, the initial value of the decision parameter is obtained by evaluating the ellipse function at the start position (x, y) = (0, ry) or CC416 Computer Graphics

18 In region 2, we sample at unit steps in the negative y direction
The midpoint is now taken between horizontal pixels at each step The decision parameter is evaluated as CC416 Computer Graphics

19 If p2k > 0, the mid-position is outside the ellipse boundary, and we select the pixel at xk
If p2k ≤ 0, the midpoint is inside or on the ellipse boundary, and we select pixel position xk+1 CC416 Computer Graphics

20 When we enter region 2, the initial position (x0, y0) is taken as the last position selected in region 1 and the initial decision parameter in region 2 is then CC416 Computer Graphics

21 To simplify the calculation of p20, we could select pixel positions in counterclockwise order starting at (rx, 0). Unit steps would then be taken in the positive y direction up to the last position selected in region 1 CC416 Computer Graphics

22 Where transformation methods can be used to reorient the ellipse
The midpoint algorithm can be adapted to generate an ellipse in nonstandard position Where transformation methods can be used to reorient the ellipse Non Standard position Standard position CC416 Computer Graphics

23 Midpoint Ellipse Algorithm
Input rx, ry and ellipse center (xc, yc), and obtain the first point on an ellipse centered on the origin as Calculate the initial value of the decision parameter in region 1 as CC416 Computer Graphics

24 At each x position in region 1, starting at k = 0, perform the following test: If p1k < 0, the next point along the ellipse centered on (0, 0) is (xk+1, yk) and Otherwise, the next point along the circle is (xk + 1, yk – 1) CC416 Computer Graphics

25 With and continue until
CC416 Computer Graphics

26 Calculate the initial value of the decision parameter in region 2 using the last point (x0, y0) calculated in region 1 as CC416 Computer Graphics

27 using the same incremental calculations for x and y as in region 1.
At each yk position in region 2, starting at k = 0, perform the following test: If p2k> 0, the next point along the ellipse centered on (0, 0) is (xk, yk - 1) and Otherwise, the next point along the circle is (xk + 1, yk - 1) and using the same incremental calculations for x and y as in region 1. CC416 Computer Graphics

28 Determine symmetry points in the other three 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 CC416 Computer Graphics

29 Example Given rx = 8 and ry = 6, rx2 = 64 and ry2 = 36
Initial values and increments for the decision parameter calculations are For region 1: The initial point for the ellipse centered on the origin is (x0, y0) = (0,6), and the initial decision parameter value is Applying the following when p1k < 0 Otherwise: Loop until CC416 Computer Graphics

30 We now move out of region 1, since
Successive decision parameter values and positions along the ellipse path are calculated using the midpoint method as We now move out of region 1, since CC416 Computer Graphics

31 For region 2 rx = 8 and ry = 6, rx2 = 64 and ry2 = 36
the initial point is (x0, y0) = (7,3) and the initial decision parameter is The remaining positions along the ellipse path in the first quadrant are then calculated as: If If p2k> 0: Else: k p2k Xk+1 Yk+1 2r2yXk+1 2r2xYk+1 -23 8 2 72*8 = 576 128*2 = 256 1 ( )= 297 576 128 ( ) = 809 - CC416 Computer Graphics

32 CC416 Computer Graphics

33 More about ellipses Source: http://en.wikipedia.org/wiki/Ellipse
CC416 Computer Graphics


Download ppt "Lecture 05: Mid-point Ellipse algorithm Dr. Manal Helal – Fall 2014"

Similar presentations


Ads by Google