You are on page 1of 12

CG (Circle Drawing)

Prof. Tathagata Ray


Associate Professor, BITS Pilani, Hyderabad Campus
BITS Pilani rayt@hyderabad.bits-pilani.ac.in
Hyderabad Campus
Basics of Circle Drawing
• Equation of a circle with center at (xc,yc) and radius r:

( x  xc)  ( y  yc)  r
2 2 2

• Parametric equation of a circle :


x  xc  r cos 
y  yc  r sin 
f ( x, y)  x  y  R
2 2 2

• f(x,y) > 0 for points outside, f(x,y) < 0 for points inside,
and f(x,y) = 0 for points on the circle

BITS Pilani, Hyderabad Campus


8-way Symmetry

Draw_circle(x,y, val)
1. Putpixel (x,y,val) (-x,y) (x,y)
2. Putpixel (-x,y,val) (-y,x)
(y,x)

3. Putpixel (x,-y,val)
4. Putpixel (-x,-y,val)
5. Putpixel (y,x,val)
6. Putpixel (-y,x,val) (-y,-x) (y,-x)
7. Putpixel (y,-x,val)
(-x,-y) (x,-y)
8. Putpixel (-y,-x,val)

BITS Pilani, Hyderabad Campus


Midpoint Circle Drawing Algo

• Assume we have just plotted pixel


at (xp,yp), we next need to
determine whether the pixel at
E (xp+1,yp) or SE (xp+1,yp-1) is
closer to the circle.
E
• Use decision parameter
yp
dold = fc(xp+1,yp-1/2)
M ME
= (xp+1)2+(yp-1/2)2-r2
SE MSE
• If dold < 0, this midpoint is inside
then we choose E.
• The next decision parameter can xp xp+1 xp+2
be obtained as dnew = fc(xp + 2, yp -
1/2) = [xp+2]2 + (yp – ½)2 – r2
• dnew = dold + 2xp+3.
• Thus, ΔE = 2xp+3.

BITS Pilani, Hyderabad Campus


Midpoint Circle Drawing Algo

• If dold > 0 this midpoint is outside


then we choose SE.
• The next decision parameter can
be obtained as
dnew = fc(xp + 2, yp -3/2) = [xp+2]2 + E
(yp – 3/2)2 – r2. yp
• dnew = dold + (2xp-2yp + 5). M ME
• Thus, ΔSE = (2xp-2yp + 5). SE MSE

xp xp+1 xp+2
• The initial parameter
P0 = fc(0+1, r – ½) = 5/4 –r
at (0,r).

BITS Pilani, Hyderabad Campus


Pseudocode

BITS Pilani, Hyderabad Campus


A simple improvement

• The algorithm given has real computations which is


expensive.
• Define a new variable h = d – ¼.
• Substitute h + ¼ for d.
• Initialization is h = 1-R, and the comparison d <0
becomes h < -1/4
• However, since h starts with an integer value and is
incremented by integer value, we can change the
comparison to just h < 0.

BITS Pilani, Hyderabad Campus


Pseudocode of line drawing

BITS Pilani, Hyderabad Campus


Integer midpoint circle scan-
conversion algorithm

BITS Pilani, Hyderabad Campus


More improvement
• We want to avoid the multiplications operations also and that can be
done using 2nd order differences which is a constant for a quadratic
function.

• If we choose E in the current iteration, the point of evaluation moves


from (xp,yp) to (xp+1,yp).

• We saw ΔEold = 2xp+3.

• Thus, ΔEnew at (xp+1,yp) = 2(xp+1)+3.

• The second-order difference is ΔEnew - ΔEold = 2.

• Similarly ΔSEold at (xp,yp) = 2(xp)-2yp + 5.

• ΔSEnew at (xp+1,yp) = 2(xp+1)-2yp + 5.

• Thus ΔSEnew - ΔSEold = 2.

BITS Pilani, Hyderabad Campus


Contd…

• If we choose SE in the current iteration, the point of


evaluation moves from (xp,yp) to (xp+1,yp -1).

• Thus, ΔEnew at (xp+1,yp-1) = 2(xp+1)+3.

• ΔEnew - ΔEold = 2.

• Also, ΔSEnew at (xp+1,yp-1) = 2(xp+1)-2(yp-1) + 5.

• Thus, ΔSEnew - ΔSEold = 4.

BITS Pilani, Hyderabad Campus


Final Algorithm

BITS Pilani, Hyderabad Campus

You might also like