Ellipse Algorithm
Ellipse Algorithm
Ellipse-Generating Algorithms
Ellipse-Generating Algorithms
d1
F1 P=(x,y)
d2
F2
( x x1 )2 ( y y1 )2 ( x x2 )2 ( y y2 )2 constant
ry
rx
2
x xc y yc
2
Cartesian coordinates: 1
rx ry
Polar coordinates: x xc rx cos
y yc ry sin
3
Ellipse Algorithms
• Symmetry between quadrants
• Not symmetric between the two octants of a quadrant
• Thus, we must calculate pixel positions along the elliptical arc
through one quadrant and then we obtain positions in the
remaining 3 quadrants by symmetry
(-x, y) (x, y)
ry
rx
Decision parameter:
0 if ( x, y ) is inside the ellipse
f ellipse ( x, y ) 0 if ( x, y ) is on the ellipse
0 if ( x, y ) is outside the ellipse
Slope = -1
1
ry 2 dy 2ry2 x
Slope 2
rx dx 2rx y
5
Ellipse Algorithms
Slope = -1
• Starting at (0, ry) we take unit steps in the x
direction until we reach the boundary between ry 1 2
region 1 and region 2. Then we take unit steps in rx
the y direction over the remainder of the curve
in the first quadrant.
• At the boundary
dy
1 2ry2 x 2rx2 y
dx
• therefore, we move out of region 1 whenever
2ry2 x 2rx2 y
6
Midpoint Ellipse Algorithm
Midpoin
yi t
yi-1
xi xi+1 xi+2
OR
p1i 1 p1i 2ry2 ( xi 1)2 ry2 rx2 ( yi 1 12 )2 ( yi 12 )2
8
Decision Parameter (Region 1)
Decision parameters are incremented by:
2
y i 1
2 r x r 2
if p1i 0
increment 2 y
2 r
y i 1x ry
2
2 r 2
x yi 1 if p1i 0
Use only addition and subtraction by obtaining
2ry2 x and 2rx2 y
Midpoint
yi
yi-1
xi xi+1 xi+2
Decision parameter:
p 2i f ellipse ( xi 12 , yi 1)
ry2 ( xi 12 )2 rx2 ( yi 1)2 rx2 ry2
If p2i > 0 the midpoint is outside the ellipse xi is closer
If p2i ≤ 0 the midpoint is inside the ellipse xi + 1 is closer
10
Decision Parameter (Region 2)
At the next position [yi+1 – 1 = yi – 2]
p 2i 1 f ellipse ( xi 1 12 , yi 1 1)
ry2 ( xi 1 12 )2 rx2 ( yi 2)2 rx2 ry2
OR
p2i 1 p2i 2rx2 ( yi 1) rx2 ry2 ( xi 1 12 )2 ( xi 12 )2
11
Decision Parameter (Region 2)
Decision parameters are incremented by:
2
x i 1 x
2 r y r 2
if p 2i 0
increment 2
2 r x
y i 1 2 r 2
y
x i 1 rx
2
if p 2i 0
p 20 f ellipse ( x0 12 , y0 1)
ry2 ( x0 12 )2 rx2 ( y0 1)2 rx2 ry2
12
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
(x0, y0) = (0, ry)
2. Calculate the initial parameter in region 1 as
p10 ry2 rx2 ry 14 rx2
6
5
4
3
2
1
0
0 1 2 3 4 5 6 7 8 16