Midpoint Ellipse Generation
Midpoint Ellipse Generation
Computer Graphics
Chapter II
Ellipse-Generation Algorithm
Dr. Sushitha Susan Joseph
Assistant Professor,
Dept. of Computer Science & Engg.,
IIIT Kottayam, Kerala – 686635.
Ellipse-Generating Algorithms
2
Ellipse-Generating Algorithms
d1
F1 P=(x,y)
d2
F2
If the distance to the two foci from any point 𝑃 = (𝑥, 𝑦)on the
ellipse are labelled as 𝑑1 and 𝑑2 then the general equation of an
ellipse can be stated as 𝑑1 + 𝑑2 = 𝑐𝑜𝑛𝑠𝑡𝑎𝑛𝑡
3
Ellipse Properties
Expressing distances d 1 and d 2 in terms of the focal coordinates F1 =(x1,
y1)and F2 =(x2,y2), we have:
(x − x ) 2 + ( y − y ) 2 + (x − x ) 2 + ( y − y ) 2 = constant
1 1 2 2
4
Ellipse Properties
Fig: Ellipse centered at(xc, yc) with semi-major axis rx and semi-minor axis ry)
The equation of the ellipse shown in the figure can be written as follows
2
𝑥−𝑥𝑐 2 𝑦−𝑦𝑐
C artesian coordinates : + =1
𝑟𝑥 𝑟𝑦
(-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
ry 1 2 dy 2ry2 x
Slope = =− 2
rx dx 2rx y
7
Ellipse Algorithms
Slope = -1
• Starting at (0, ry) we take unit steps in the x direction untilwe
reach the boundary between region 1 and region 2.Then ry 1 2
we take unit steps in the y direction over the remainder of rx
the c urve in the firstquadrant.
• At the boundary between region 1 and region 2
dy = −1 2r 2 x = 2r 2 y
y x
dx
• therefore, we move out of region 1 whenever 2𝑟𝑦 2 𝑥 ≥ 2𝑟𝑥 2 𝑦
8
Midpoint Ellipse Algorithm
Midpoin
yi t
yi-1
xi xi+1 xi+2
Assuming that we have just plotted the pixels at (xi , yi). The next position is
determined by: p1i = f ellipse (xi +1, yi − 1)
2
= r 2 (x +1) 2 + r 2 ( y − 1 ) 2 − r 2 r 2
y i x i 2 x y
OR
p1i+1 = p1i + 2ry2 (xi +1) 2 + ry2 + rx2 ( yi+1 − 12 ) 2 − ( yi − 12 ) 2
1
0
Decision Parameter (Region 1)
• Decision parameters are incremented by:
2 r x i +12 + r2 if p1 0
increment = y
2 + r
y
2
− 2 r 2
y
i
if p1 0
2 r x i +1
y y x i+1 i
2 ry2 x = 0
2 rx2 y = 2 rx2 r y
1 2 2 −
p10 = f ellipse (1, ry − ) = r + r (r y 2
1 )2 − r 2r 2
2 y x x y
9
= ry2 − rx2 ry + 14 rx2
Region 2
Over region 2, step in the negative y direction and midpoint is
taken between horizontal pixels at each step.
Midpoint
yi
yi-1
xi xi+1 xi+2
Decision parameter:
p2 i = f ellipse (x i + 2 , y i −1)
1
= r 2 ( x + 1 ) 2 + r 2 ( y − 1) 2 − r 2 r 2
y i 2 x i x y
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
12
Decision Parameter (Region 2)
At the next position [yi+1 – 1 =yi – 2]
p2i+1 = f ellipse (xi+1 + 12 , yi+1 −1)
= r 2 (x + 1 ) 2 + r 2 ( y − 2) 2 − r 2 r 2
y i+1 2 x i x y
OR
p2i+1 = p2i − 2rx2 ( yi −1) + rx2 + ry2 (xi+1 + 12 ) 2 − (xi + 12 ) 2
13
Decision Parameter (Region 2)
Decision parameters are incremented by:
2r yi+1 x2 + r 2
if p2 0
increment = 2 x
− 2r 2
y + r 2
i
if p2 0
2ry xi+1 x i+1 x i
= r 2 (x + 1 ) 2 + r 2 ( y −1) 2 − r 2 r 2
y 0 2 x 0 x y
14
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
p1 = r 2 − r 2 r + 1 r 2
0 y x y 4 x
i pi xi+1, yi+1
0 -23 (8, 2)
1 361 (8, 1)
2 169 (8, 0) Stop at y = 0
6
5
4
3
2
1
0
0 1 2 3 4 5 6 7 8 20