CS335 Computer Graphics: Circle and Ellipse Drawing Algorithms
CS335 Computer Graphics: Circle and Ellipse Drawing Algorithms
Spiral Drawing
Ellipse Drawing
Table of contents
1 Circle Drawing
Circle Drawing
Midpoint Circle Drawing Algorithm
2 Spiral Drawing
Spiral Drawing
3 Ellipse Drawing
Ellipse Drawing
Midpoint Ellipse Drawing Algorithm
Equation of a circle
Drawing a circle
Drawing a circle
Drawing a circle
How to vary ?
We are aiming to plot
4r 4 points
Step size for varying
is 2/4(r 1)
Computation can be
reduced by exploiting
symmetry
Drawing a circle
Drawing a circle
y = yc r 2 (xc x)2
x = xc r 2 (yc y )2
Uneven plotting wont be there if we plot 1/8th of a circle!
Each pixel computation would need 3 addition (or
subtraction) and 3 exponentiation (or root) operation
fcircle = x 2 + y 2 r 2
Without loss of generalization, we consider center at (0, 0)
< 0; if (x, y ) is inside the boundary
fcircle (x, y ) = = 0; if (x, y ) is on the boundary
> 0; if (x, y ) is outiside the boundary
pk+1
= fcircle (xk+1 + 1, yk+1 12 )
= [(xk + 1) + 1]2 + (yk+1 12 )2 r 2
2
pk+1 = pk + 2(xk + 1) + (yk+1 yk2 ) (yk+1 yk ) + 1
2
pk+1 = pk + 2(xk + 1) + (yk+1 yk2 ) (yk+1 yk ) + 1
When pk was negetive, i.e. yk+1 = yk , pk+1 = pk + 2xk+1 + 1
When pk was positive, i.e. yk+1 = yk + 1,
pk+1 = pk + 2xk+1 + 1 2yk+1
Evaluation of xk+1 and yk+1 can be done as follows:
2xk+1 = 2xk + 2 and 2yk+1 = 2yk 2 when we start from
(0, r ) and move towards ( r 2 , r 2 )
p0
= fcircle (1, r 21 )
= 12 + (r 12 )2 r 2
= 54 r
= 1 r (rounding p0 for an integer value of r )
Starting from (0, r ), stop when x > y
1 Input: r
2 (x0 , y0 ) (0, r )
3 Load (x0 , y0 )
4 p0 (1 r )
5 k0
6 if (pk < 0)
xk+1 xk + 1, yk+1 yk , Load (xk + 1, yk )
pk+1 pk + 2xk+1 + 1 OR pk+1 pk + 2xk + 3
7 Otherwise
xk+1 xk + 1, yk+1 yk 1, Load (xk + 1, yk 1)
pk+1 pk + 2xk+1 + 1 2yk+1 OR pk+1 pk + 2xk + 5 2yk
8 k (k + 1)
9 Repeat steps 6,7,8 while xk yk
x y x + xc y + yc
0 10 3 14
1 10 4 14
Shifting center 2 10 5 14
at (3, 4) 3 10 6 14
4 9 7 13
5 9 8 13
6 8 9 12
7 7 10 11
Spiral Drawing
Spiral Drawing
x = xc + r cos
y = yc + r sin
(router rinner )
r = 2 keeps on recomputed as intermediate value
of r
How to vary ?
We aim to plot 4r 4 points for a circle with radius r
Step size for varying is 2/4(r 1)
Equation of an ellipse
Drawing an ellipse
Drawing an ellipse
How to vary ?
We are aiming to plot p = max(4rx 4, 4rx 4) points
Step size for varying is 2/p
Computation can be reduced by exploiting symmetry
< 0; if (x, y ) is inside the boundary
fellipse (x, y ) = = 0; if (x, y ) is on the boundary
> 0; if (x, y ) is outiside the boundary
dy 2r 2 x
Slope of ellipse at (x, y ) = dx = 2ry2 y
x
p1k
= fellipse (xk + 1, yk 21 )
= ry2 (xk + 1)2 + rx2 (yk 12 )2 rx2 ry2
p1k+1
= fellipse (xk+1 + 1, yk+1 12 )
=
ry2 [(xk +1)+1]2 +rx2 (yk+1 21 )2 rx2 ry2
p1k+1
= p1k + 2ry2 (xk + 1) + ry2 +
rx2 [(yk+1 21 )2 (yk 21 )2 ]
IF p1k < 0
yk+1 = yk
p1k+1 = p1k + 2ry2 xk+1 + ry2
OTHERWISE
yk+1 = yk 1 Figure: Decision parameter in
p1k+1 = p1k +2ry2 xk+1 +ry2 2rx2 yk+1 Region 1
Finding p10
p10
= fellipse (1, ry 21 )
= ry2 + rx2 (ry 12 )2 rx2 ry2
rx2
= ry2 rx2 ry + 4
p2k
= fellipse (xk + 21 , yk 1)
= ry2 (xk + 12 )2 + rx2 (yk 1)2 rx2 ry2
p2k+1
= fellipse (xk+1 + 12 , yk+1 1)
=
ry2 (xk+1 + 12 )2 +rx2 [(yk 1)1]2 rx2 ry2
p2k+1
= p2k 2rx2 (yk 1) + rx2 +
ry2 [(xk+1 + 21 )2 (xk + 21 )2 ]
IF p2k > 0
xk+1 = xk
p2k+1 = p2k 2rx2 yk+1 + rx2
OTHERWISE
xk+1 = xk + 1 Figure: Decision parameter in
p2k+1 = p2k 2rx2 yk+1 +rx2 +2ry2 xk+1
Region 2
Finding p20
p20
= fellipse (x0 + 21 , y0 1)
= ry2 (x0 + 12 )2 + rx2 (y0 1)2 rx2 ry2
(x0 , y0 ) is the last point of Region 1.
rx4 ry4
(x0 , y0 ) = ( r 2 +r 2
, r 2 +r 2
)
x y x y