0% found this document useful (0 votes)
9 views24 pages

CSC308 Lec10 Computer Graphics

Uploaded by

alihassenttyy3
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)
9 views24 pages

CSC308 Lec10 Computer Graphics

Uploaded by

alihassenttyy3
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/ 24

Computer Graphics

CS 308
Spring 24-25

Lecture 10
Ellipse Generating Algorithms

Instructor
Dr / Ayman Soliman
➢ Contents
1) Properties of Ellipses

2) Midpoint Ellipse Algorithm

3) Example

4) Ellipse code

2025-04-16 Dr/ Ayman Soliman 2


❑ Properties of Ellipses
➢ A precise definition of an ellipse can be given in terms of the distances from any
point on the ellipse to two fixed positions, called the foci of the ellipse.

𝑑1 + 𝑑2 = 𝑐𝑜𝑛𝑠𝑡𝑎𝑛𝑡. (1)

Expressing distances d1 and d2

(𝑥 − 𝑥1 )2 +(𝑦 − 𝑦1 )2 + (𝑥 − 𝑥2 )2 +(𝑦 − 𝑦2 )2 = 𝑐𝑜𝑛𝑠𝑡𝑎𝑛𝑡

➢ The general ellipse equation in the form

𝐴𝑥 2 + 𝐵𝑦 2 + 𝐶𝑥𝑦 + 𝐷𝑥 + 𝐸𝑦 + 𝐹 = 0

2025-04-16 Dr/ Ayman Soliman 3


❑ Properties of Ellipses
➢ The major axis is the straight-line segment extending from
one side of the ellipse to the other through the foci. The
minor axis spans the shorter dimension of the ellipse.

➢ The equation for the ellipse

𝑥−𝑥𝑐 2 𝑦−𝑦𝑐 2
( ) +( ) = 1. (1)
𝑟𝑥 𝑟𝑦

2025-04-16 Dr/ Ayman Soliman 4


❑ Properties of Ellipses
➢ Using polar coordinates r and 𝜃

𝑥 = 𝑥𝑐 + 𝑟𝑥 cos 𝜃. (2)

y= 𝑦𝑐 + 𝑟𝑦 sin 𝜃 (2)

➢ If rx > ry, the radius of the bounding circle is r = rx .

➢ Otherwise, the bounding circle has radius r = ry.


➢ As with the circle algorithm, symmetry considerations can be used to 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 use symmetry to obtain curve positions in the remaining three
quadrants
2025-04-16 Dr/ Ayman Soliman 5
❑ Midpoint Ellipse Algorithm
➢ Given parameters rx , ry, and (xc,yc), we determine
curve positions (x,y) for an ellipse in standard
position centered on the origin, then we shift all
the points using a fixed offset so that the ellipse is
centered at (xc,yc).

➢ If we wish also to display the ellipse in


nonstandard position, we could rotate the ellipse
about its center coordinates to reorient the major
and minor axes in the desired directions.
2025-04-16 Dr/ Ayman Soliman 6
❑ Midpoint Ellipse Algorithm
➢ Regions 1 and 2 can be processed in various ways. We can
start at position (0,ry) and step clockwise along the elliptical
path in the first quadrant, shifting from unit steps in x to unit
steps in y when the slope becomes less than -1.0.

➢ Alternatively, we could start at (rx,0) and select points in a


counterclockwise order, shifting from unit steps in y to unit
steps in x when the slope becomes greater than -1.0. With
parallel processors, we could calculate pixel positions in the
two regions simultaneously.
2025-04-16 Dr/ Ayman Soliman 7
❑ Midpoint Ellipse Algorithm
➢ As an example of a sequential implementation of the
midpoint algorithm, we take the start position at (0,ry) and
step along the ellipse path in clockwise order throughout
the first quadrant.

2025-04-16 Dr/ Ayman Soliman 8


❑ Midpoint Ellipse Algorithm
➢ We define an ellipse function from Equation ( 2 ) with (xc , yc) = (0, 0) as

𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 (𝑥, 𝑦) = 𝑟𝑦2 𝑥 2 + 𝑟𝑥2 𝑦 2 − 𝑟𝑥2 𝑟𝑦2 (3)

➢ which has the following properties:

< 0. 𝑖𝑓 𝑥, 𝑦 𝑖𝑠 𝑖𝑛𝑠𝑖𝑑𝑒 𝑡ℎ𝑒 𝑒𝑙𝑙𝑖𝑝𝑠𝑒 𝑏𝑜𝑢𝑛𝑑𝑎𝑟𝑦


𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 𝑥, 𝑦 ൞ = 0. 𝑖𝑓 𝑥, 𝑦 𝑖𝑠 𝑜𝑛 𝑡ℎ𝑒 𝑒𝑙𝑙𝑖𝑝𝑠𝑒 𝑏𝑜𝑢𝑛𝑑𝑎𝑟𝑦 . (4)
> 0. 𝑖𝑓 𝑥, 𝑦 𝑖𝑠 𝑜𝑢𝑡𝑠𝑖𝑑𝑒 𝑡ℎ𝑒 𝑒𝑙𝑙𝑖𝑝𝑠𝑒 𝑏𝑜𝑢𝑛𝑑𝑎𝑟𝑦

2025-04-16 Dr/ Ayman Soliman 9


❑ Midpoint Ellipse Algorithm
➢ Starting at (0,ry), we take unit steps in the x direction until we reach the boundary
between region 1 and region 2. Then we switch to unit steps in the y direction over
the remainder of the curve in the first quadrant. At each step we need to test the
value of the slope of the curve. The ellipse slope is calculated from Equation (3) as

𝑑𝑦 2𝑟𝑦2 𝑥
= 2 (5)
𝑑𝑥 2𝑟𝑥 𝑦
𝑑𝑦
➢ At the boundary between region -1 and region 2 and = -1 and
𝑑𝑥
2𝑟𝑦2 𝑥= 2𝑟𝑥2 𝑦 (6)
➢ Therefore, we move out of region 1 whenever

2𝑟𝑦2 𝑥 ≥ 2𝑟𝑥2 𝑦
2025-04-16 Dr/ Ayman Soliman 10
❑ Midpoint Ellipse Algorithm
➢ The decision parameter (that is, the ellipse function 3) at this midpoint:

1
𝑝1𝑘 = 𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 𝑥𝑘 + 1 , 𝑦𝑘 − 7
2

1
= 𝑟𝑦2 (𝑥𝑘 + 1)2 +𝑟𝑥2 (𝑦𝑘 − )2 −𝑟𝑥2 𝑟𝑦2 . (7)
2

➢ If p1k<0, the midpoint is inside the ellipse and the pixel on scan line yk is closer to
the ellipse boundary. Otherwise, the midposition is outside or on the ellipse
boundary, and we select the pixel on scan line yk = −1.

2025-04-16 Dr/ Ayman Soliman 11


❑ Midpoint Ellipse Algorithm
➢ At the next sampling position (xk+1 + 1 = xk + 2), the decision parameter for region 1
is evaluated as
1
𝑝1𝑘+1 = 𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 𝑥𝑘+1 + 1 , 𝑦𝑘+1 − 8
2
1 2
= 𝑟𝑦 [ 𝑥𝑘+1 + 1] +𝑟𝑥 (𝑦𝑘+1 − ) − 𝑟𝑥2 𝑟𝑦2 (8)
2 2 2
2
Or

2 2
1 1
𝑝1𝑘+1 = 𝑝1𝑘 + 2𝑟𝑦2 𝑥𝑘 + 1 + 𝑟𝑦2 + 𝑟𝑥2 𝑦𝑘+1 − − 𝑦𝑘 − (8)
2 2

➢ where yk+1 is either yk or yk − 1, depending on the sign of p1k.


2025-04-16 Dr/ Ayman Soliman 12
❑ Midpoint Ellipse Algorithm
➢ Decision parameters are incremented by the following amounts:

2𝑟𝑦2 𝑥𝑘+1 + 𝑟𝑦2 𝑖𝑓 𝑝1𝑘 < 0 (9)


𝑖𝑛𝑐𝑟𝑒𝑚𝑒𝑛𝑡 = ൝ 2
2𝑟𝑦 𝑥𝑘+1 + 𝑟𝑦2 − 2𝑟𝑥2 𝑦𝑘+1 𝑖𝑓 𝑝1𝑘 ≥ 0 (9)

➢ At the initial position (0, ry), these two terms evaluate to

2𝑟𝑦2 𝑥 = 0 10

2𝑟𝑥2 𝑦 = 2𝑟𝑥2 𝑟𝑦 . (10)

2025-04-16 Dr/ Ayman Soliman 13


❑ Midpoint Ellipse Algorithm
➢ In region 1, the initial value of the decision parameter is obtained by evaluating
the ellipse function at the start position (x0, y0) = (0, ry):

1
𝑝10 = 𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 1 , 𝑟𝑦 − . 11
2

1 2
= 𝑟𝑦2 + 𝑟𝑥2 (𝑟𝑦 − ) −𝑟𝑥2 𝑟𝑦2 . 11
2
Or

1 2
𝑝10 = 𝑟𝑦2 − 𝑟𝑥2 𝑟𝑦 + 𝑟𝑥 (11)
4
2025-04-16 Dr/ Ayman Soliman 14
❑ Midpoint Ellipse Algorithm
➢ Over region 2, we sample at unit intervals in the negative y direction, and the
midpoint is now taken between horizontal pixels at each step (Figure ). For this
region, the decision parameter is evaluated as
1
𝑝2𝑘 = 𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 (𝑥𝑘 + , 𝑦𝑘 − 1)
2
1 2 2
= 𝑟𝑦 (𝑥𝑘 + ) +𝑟𝑥 (𝑦𝑘 − 1)2 −𝑟𝑥2 𝑟𝑦2
2
2

1
𝑝2𝑘+1 = 𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 (𝑥𝑘+1 + , 𝑦𝑘+1 − 1)
2
1 2 2
= 𝑟𝑦 (𝑥𝑘+1 + ) +𝑟𝑥 (𝑦𝑘−1 − 1)2 −𝑟𝑥2 𝑟𝑦2
2
2

2025-04-16 Dr/ Ayman Soliman 15


❑ Midpoint Ellipse Algorithm
Or
2 2
1 1
𝑝2𝑘+1 = 𝑝2𝑘 − 2𝑟𝑥2 𝑦𝑘 − 1 + 𝑟𝑥2 + 𝑟𝑦2 [ 𝑥𝑘+1 + − 𝑥𝑘 + ]
2 2

1
𝑝20 = 𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 𝑥0 + , 𝑦0 − 1
2
1 2 2
= 𝑟𝑦2 (𝑥0 + ) +𝑟𝑥 (𝑦0 − 1)2 −𝑟𝑥2 𝑟𝑦2
2

2025-04-16 Dr/ Ayman Soliman 16


❑ Midpoint Ellipse Algorithm

2025-04-16 Dr/ Ayman Soliman 17


❑ Midpoint Ellipse Algorithm

2025-04-16 Dr/ Ayman Soliman 18


❑ Example: Midpoint Ellipse Drawing (Textbook P114-115)
➢ Given input ellipse parameters rx=8 and ry=6, we illustrate the steps in the

midpoint ellipse algorithm by determining raster positions along the ellipse path

in the first quadrant. Initial values and increments for the decision parameter

calculations are

2025-04-16 Dr/ Ayman Soliman 19


❑ Example: Midpoint Ellipse Drawing (Textbook P114-115)

2025-04-16 Dr/ Ayman Soliman 20


❑ Example: Midpoint Ellipse Drawing (Textbook P114-115)

2025-04-16 Dr/ Ayman Soliman 21


❑ Example: Midpoint Ellipse Drawing (Textbook P114-115)

2025-04-16 Dr/ Ayman Soliman 22


❑ Ellipse code

2025-04-16 Dr/ Ayman Soliman 23


2025-04-16 Dr/ Ayman Soliman 24

You might also like