Computer Graphics CC416 Week 04 Mid-point Ellipse algorithm
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
2
• Start with the basic equation of a circle
• Divide both sides by
yc
r2
ry (x,y) r x
xc
• The general equation of an ellipse can be stated as CC416 Computer Graphics
3
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
d2 d1
CC416 Computer Graphics
4
• So d2 d1
• Expressing distances d1, and d2, in terms of the focal coordinates F1 = (x1, y1) and F2 = (x2, y2), we have CC416 Computer Graphics
5
• 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
6
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
7
• 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
8
• From equation
• When (xc, yc) = (0,0)
• the decision parameter will be according to
CC416 Computer Graphics
9
• 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
10
• 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
11
• At the boundary between region 1 and region 2, dy/dx = - 1 and
• Therefore, we move out of region 1 whenever CC416 Computer Graphics
12
• 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
13
• 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
14
• At the next sampling position (xk+1+1 = xk + 2), the decision parameter for region 1 is evaluated as
• where yk+1 is either yk or yk - 1, depending on the sign of p1k CC416 Computer Graphics
15
• So decision parameters are incremented by the following amounts:
CC416 Computer Graphics
16
• 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
17
• In region 2, we sample at unit steps in the negative y direction • Th midpoint is now taken between horizontal pixels at each step • The decision parameter is evaluated as
CC416 Computer Graphics
18
• 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
19
• When we enter region 2, ;he initial position (x0, y0) is taken as the last position selected in region 1 and the initial derision parameter in region 2 is then
CC416 Computer Graphics
20
• 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
21
• 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
22
• Midpoint Ellipse Algorithm 1. Input rx, ry and ellipse center (xc, yc), and obtain the first point on an ellipse centered on the origin as
2. Calculate the initial value of the decision parameter in region 1 as CC416 Computer Graphics
23
2. 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
24
With
and continue until
CC416 Computer Graphics
25
4. 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
26
5. 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
27
6. Determine symmetry points in the other three quadrants. 7. 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
28
• Example – Given rx = 8 and ry = 6 – 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 CC416 Computer Graphics
29
• 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
30
– For region 2 • 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
CC416 Computer Graphics
31
CC416 Computer Graphics
32
More about ellipses • Source: http://en.wikipedia.org/wiki/Ellipse
CC416 Computer Graphics
33
CC416 Computer Graphics
34