CSC308 Lec10 Computer Graphics
CSC308 Lec10 Computer Graphics
CS 308
Spring 24-25
Lecture 10
Ellipse Generating Algorithms
Instructor
Dr / Ayman Soliman
➢ Contents
1) Properties of Ellipses
3) Example
4) Ellipse code
𝑑1 + 𝑑2 = 𝑐𝑜𝑛𝑠𝑡𝑎𝑛𝑡. (1)
𝐴𝑥 2 + 𝐵𝑦 2 + 𝐶𝑥𝑦 + 𝐷𝑥 + 𝐸𝑦 + 𝐹 = 0
𝑥−𝑥𝑐 2 𝑦−𝑦𝑐 2
( ) +( ) = 1. (1)
𝑟𝑥 𝑟𝑦
𝑥 = 𝑥𝑐 + 𝑟𝑥 cos 𝜃. (2)
y= 𝑦𝑐 + 𝑟𝑦 sin 𝜃 (2)
𝑑𝑦 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.
2 2
1 1
𝑝1𝑘+1 = 𝑝1𝑘 + 2𝑟𝑦2 𝑥𝑘 + 1 + 𝑟𝑦2 + 𝑟𝑥2 𝑦𝑘+1 − − 𝑦𝑘 − (8)
2 2
2𝑟𝑦2 𝑥 = 0 10
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
1
𝑝20 = 𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 𝑥0 + , 𝑦0 − 1
2
1 2 2
= 𝑟𝑦2 (𝑥0 + ) +𝑟𝑥 (𝑦0 − 1)2 −𝑟𝑥2 𝑟𝑦2
2
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