0% found this document useful (0 votes)
31 views20 pages

Midpoint Ellipse Generation

Mid point ellipse generation

Uploaded by

Moturu Karthik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views20 pages

Midpoint Ellipse Generation

Mid point ellipse generation

Uploaded by

Moturu Karthik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

CSE411

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

 An ellipse is an elongated circle


 Ellipse is defined as a set of points such that the sum of the
distances from two fixed positions (foci) is the same for all
points.
 An ellipse is similar to a circle but its stretched vertically or
horizontally by equal amounts.

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
𝑟𝑥 𝑟𝑦

Polar coordinates : x = xc + rx cos 


y = yc + ry sin 
5
Ellipse Algorithms
• Symmetric between quadrants
• Not symmetric between the two octants of a quadrant as in circle
• 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

(-x, -y) (x, -y)


6
Midpoint Ellipse Algorithms
f (x, y) = r 2 x 2 + r 2 y 2 − r 2 r 2
ellipse y x x y

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

If 𝑝1𝑖 < 0, the midpoint is inside the ellipse then yi is closer


If 𝑝1𝑖 > 0 ,the midpoint is outside the ellipse then yi – 1 is closer 9
Decision Parameter (Region 1)
At the next position [xi+1 +1 =xi +2]
p1i+1 = fellipse (xi+1 +1, yi+1 − 12 )
= r 2 (x + 2) 2 + r 2 ( y − 1 ) 2 − r 2 r 2
y i x i+1 2 x y

OR
p1i+1 = p1i + 2ry2 (xi +1) 2 + ry2 + rx2 ( yi+1 − 12 ) 2 − ( yi − 12 ) 2 

where yi+1 =yi or yi+1 =yi – 1

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

• At initial position (0, ry)

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 

where xi+1 =xi or xi+1 =xi +1

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

At initial position (x0, y0) is taken at the last


position selected in region 1

p20 = f ellipse (x0 + , y0 −1)


1
2

= 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

3. At each xi position, starting at i =0, if p1i <0, the next


point along the ellipse centered on (0, 0) is (xi +1, yi) and
p1 = p1 + 2r 2 x + r2
i+1 i y i+1 y

otherwise, the next point is (xi +1, yi – 1) and


p1 = p1 + 2r 2 x − 2r 2 y + r2
i+1 i y i+1 x i+1 y

and c ontinue until


2r 2
x  2r 2
y 13
y x
Midpoint Ellipse Algorithm
4. (x0, y0) is the last position calculated in region 1.
Calculate the initial parameter in region 2 as
p20 = ry2 (x0 + 12 ) 2 + rx2 ( y0 −1) 2 − rx2 ry2
5. At each yi position, starting at i =0, if p2i >0, the next
point along the ellipse centered on (0, 0) is (xi, yi – 1) and
p2 = p2 − 2r 2 y + r2
i+1 i x i+1 x
otherwise, the next point is (xi +1, yi – 1) and
p2 = p2 + 2r 2 x − 2r 2 y + r2
i+1 i y i+1 x i+1 x

Use the same incremental calculations as in region 1.


Continue until y =0.
6. For both regions 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
16
Example
Given input ellipse parameters 𝑟𝑥 = 8 and 𝑟𝑦 =
6 . Generate ellipse using midpoint method
in first quadrant.
rx = 8 , ry = 6
Example 2ry2x = 0 (with increment 2r y2 = 72)
2
2 2
2rx y = 2rx ry (with increment -2rx = -128)
i pi xi+1, yi+1 2ry2xi+1 2rx2yi+1
Region 1
0 -332 (1, 6) 72 768 (x0, y0) = (0, 6)
1 -224 (2, 6) 144 768 p1 = r 2 − r 2 r + 1 r 2 = −332
0 y x y 4 x
2 -44 (3, 6) 216 768
3 208 (4, 5) 288 640 Move out of region 1 since
4 -108 (5, 5) 360 640 2ry2x > 2r x2y
5 288 (6, 4) 432 512
6 244 (7, 3) 504 384 6    
5  
4 
3 
2
1
0
0 1 2 3 4 5 6 7 8
19
Example
Region 2
(x0, y0) = (7, 3) (Last position in region 1) p2 0 = −23

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

You might also like