Computer Graphics Lec - 2

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

Circle Drawing Algorithm

Using circle equation


Using Bresenhams Circle Drawing algorithm

Circle Drawing Algorithm

The equation of Circle is given by


(x a)2 + (y - b)2 = r2 -------------------(1)

Bresenhams Circle Drawing algorithm


The Circle function is given by
f(x,y) = x2 + y2 r2
Let (x1, y1) be a point on the circle, then
f ( x1, y1) = 0
on the Circle
<0
inside the circle
>0
outside the circle
So we may conclude that function may be taken as
decision parameter
Contd.
3

(Xk,Yk)

Yk

(Xk+1,Yk+1)
Either
Xk+1

(Yk)

or
(Yk-1)

Yk 1/2

Yk - 1

Xk

Xk+1

The decision parameter (Pk) is determined at the mid point


between the pixel Yk and Yk 1 , which is given by
Pk = f( xk+1, yk )
= (xk+1)2 + (yk )2 - r2
if Pk < 0 ,then the next point is (Xk+1, Yk)
mid point is inside the circle
otherwise the next point is (Xk+1, Yk 1)
the mid point is outside or on the circle boundary.

Now we will calculate the successive decision parameter


using incremental calculation as At sampling position (X K+1 + 1)
i.e. Xk + 2, the decision parameter is given by
P k+1 = f(X k+1 +1,Yk+1 )
= (X k+1 +1)2 + (Yk+1 ) 2 - r2
where Yk+1 is either Yk or Yk-1 depending the on the sign of
Pk .
Hence
Pk+1 Pk = [(Xk+1 +1)2 +(Yk+1 ) 2 ] - [(xk+1)2 + (yk )2]
= 2.Xk+1 +1 + (Yk+12 - Yk2 ) (Yk+1 - Yk)

When Pk < 0, then Yk+1 = Yk , then


Pk+1 - Pk = 2xk+1 + 1
When Pk 0, then Yk+1 = Yk 1 , then
Pk+1 - Pk = 2xk+1 + 1 + [(Yk-1)2 Yk2] - [Yk-1 Yk]
= 2xk+1 + 1 + [Yk2 2Yk + 1 Yk2] + 1
= 2xk+1 2(Yk 1) + 1
= 2xk+1 2Yk+1 + 1 [ Putting Yk+1 = Yk 1 ]

Starting decision parameter :The initial decision parameter is obtained by evaluating


the circle function at the start position,
Say (X0,Y0) = (0,r)
Then P0 = f(0+1, r - )
= 5/4 r 1 r ( for r an integer)

Bresenhams Circle Drawing algorithm


The steps are :1.
2.
3.
4.

5.
6.
7.

Input radius r and circle centre (a, b) and find the first point on the
circumference of a circle centered as origin (X0,Y0) = (0,r)
To calculate initial value of the decision parameter
P0 = 5/4 r 1 r
At each Xk position starting at k = 0 perform the following test : If Pk < 0, then the next point is (Xk+1,Yk) and
Pk+1 = Pk + 2.X K+1 + 1
otherwise, the next point along the circle is (Xk+1, Yk+1) and
Pk+1 = Pk + 2.Xk+1 2.Yk+1 + 1
= Pk + 2.(Xk+1 Yk+1) + 1 where Xk+1 = XK+ 1
Yk+1 = YK - 1
Determine the Symmetry points
Move each calculated pixel position onto the circular path,centered on
(a, b) and plot the co ordinate values as x = x+a and y = y+b
Repeat the steps 3 through 5 until x y

You might also like