You are on page 1of 21

Circle Drawing Algorithm

CSE2066 – Computer Graphics


Module 1
Introduction
• It is not easy to display a continuous smooth arc on the computer screen as
our computer screen is made of pixels organized in matrix form.
• So, to draw a circle on a computer screen we should always choose the
nearest pixels from a printed pixel so as they could form an arc.
• There are two algorithm to do this:
1.Mid-Point circle drawing algorithm
2.Bresenham’s circle drawing algorithm
Properties of Circle
• A circle is defined as the set of points that are all at a given distance r from a
center position (xc , yc ).
• For any circle point (x, y), this distance relationship is expressed by the
Pythagorean theorem in Cartesian coordinates as
• (x − xc)**2 + (y − yc)**2 = r **2
• Expressing the circle equation in parametric polar form yields the pair of
equations
• x = xc + r cos θ
• y = yc + r sin θ
Cont…
• can reduce computations by considering the symmetry of circles
• The shape of the circle is similar in each quadrant
• if we determine the curve positions in the first quadrant, we can generate the
circle section in the second quadrant of the xy plane by noting that the two
circle sections are symmetric with respect to the y axis.
• Also, circle sections in the third and fourth quadrants can be obtained from
sections in the first and second quadrants by considering symmetry about the
x axis.
• i.e. there is a symmetry between octants
Mid-Point circle drawing algorithm
• an algorithm used to determine the points needed for rasterizing a circle
• Given the center point (X0, Y0) and radius of circle , Mid Point Circle Drawing Algorithm
attempts to generate the points of one octant.
• The points for other octants are generated using the eight symmetry property
• Step-01: Assign the starting point coordinates (X0, Y0) as-
• X0 = 0
• Y0 = R 
• Step-02: Calculate the value of initial decision parameter P0 as-
• P0 = 1 – R
•  Step-03:  Suppose the current point is (Xk, Yk) and the next point is (Xk+1, Yk+1).
• Find the next point of the first octant depending on the value of decision parameter P k.
Cont…
• Step-04: If the given centre point (X0, Y0) is not (0, 0), then do the following and plot
the point-
• Xplot = Xc + X0
• Yplot = Yc + Y0 , Here, (Xc, Yc) denotes the current value of X and Y coordinates.
• 
• Step-05: Keep repeating Step-03 and Step-04 until Xplot >= Yplot.
• 
• Step-06:  
• Step-05 generates all the points for one octant.
• To find the points for other seven octants, follow the eight symmetry property of
circle.
Bresenham’s circle drawing algorithm
• This algorithm uses the key feature of circle that it is highly symmetric. 
• So, for whole 360 degree of circle we will divide it in 8-parts each octant of 45 degree.
• In order to do that we will use Bresenham’s Circle Algorithm for calculation of the
locations of the pixels in the first octant of 45 degrees.
• It assumes that the circle is centered on the origin.
• So for every pixel (x, y) it calculates, we draw a pixel in each of the 8 octants of the circle
as shown below :

8
• Now, we will see how to calculate the next pixel
location from a previously known pixel location (x, y).
• In Bresenham’s algorithm at any point (x, y) we have
two option either to choose the next pixel in the east
i.e. (x+1, y) or in the south east i.e. (x+1, y-1).
 

9
• And this can be decided by using the decision
parameter d as:
• If d > 0, then (x+1, y-1) is to be chosen as the next pixel
as it will be closer to the arc.
• else (x+1, y) is to be chosen as next pixel.
WHERE
d=3–2xR

10
• Thus the points generated using Bresenham Circle
Drawing Algorithm involves the following steps:
Step 1 : Set initial values of (xc, yc) and (x, y)
Step 2 : Calculate decision parameter d to d = 3 – (2 * r).
Step 3 : call displayBresenhmCircle(int xc, int yc, int x, int y) method to display
initial(0,r) point.

Step 4 : Repeat steps 5 to 8 until x < = y


Step 5 : Increment value of x.
Step 6 : If dk < 0,
set dk+1 = dk + (4*xk) + 6
xk+1 = xk+1
Else if dk>=0,
set dk+1 = dk + 4 * (xk – Yk) + 10
xk+1 = xk+1
Yk+1 = Yk - 1
Step 7 : call displayBresenhmCircle(int xc, int yc, int x, int y) Step 8 :
Exit.

11
Problems
1. Given the centre point coordinates (0, 0) and radius as 8, generate all
the points to form a circle.

2. Given the centre point coordinates (10, 10) and radius as 10,
generate all the points to form a circle.

12
Solution for Problem 1
• Given-
Centre Coordinates of Circle (X0, Y0) = (0, 0)
Radius of Circle = 8
• Step-01:
Assign the starting point coordinates (X0, Y0) as-
X0 = 0
Y0 = R = 8

13
• Step-02:
Calculate the value of initial decision parameter d as-
d0 = 3 – 2 x R
d0 = 3 – 2 x 8
d0 = -13

14
• Step-03:
As d0 < 0, so case-01 is satisfied.
Thus,
X  = X  + 1 = 0 + 1 = 1
k+1 k

Y  = Y  = 8
k+1 k

d  = d  + 4 x X  + 6
k+1 k k+1

d1 = d0 + 4( X1 )+ 6
= -13 + 4(1) + 6 = -3

15
dk dk+1 (Xk+1, Yk+1)
(0, 8)
-13 -3 (1, 8)

Step-04:
This step is not applicable here as the given centre
point coordinates is (0, 0).
Repeat step-05 until xk+1 >=yk+1.

16
• Step-05:
Since d1 < 0, case - 01 is applied.
So, X2 = X1+1 = 1 + 1 = 2
Y2 = Y 1 = 8
d2 = d1 + 4(X2) + 6
= -3 + 4(2) + 6
= 11

17
dk dk+1 (Xk+1, Yk+1)

(0, 8)

-13 -3 (1, 8)

-3 11 (2, 8)

Algorithm Terminates
These are all points for Octant-1.

18
• Step-05(repeat):
Since d2 >= 0, case - 02 is applied.
So, X3 = X2+1 = 2 + 1 = 3
Y3 = Y2 -1 = 8 – 1 = 7
d3 = d2 + 4(X3 – Y3) + 10
= 11 + 4(3 - 7) + 10
=5

19
Advantages and Disadvantages
• Advantages
• The Bresenhem’s circle drawing algorithm uses integer arithmetic which
makes the implementation less complex.
• Due to its integer arithmetic, it is less time-consuming.
• This algorithm is more accurate than any other circle drawing algorithm as it
avoids the use of round off function.

• Disadvantages
• This algorithm does not produce smooth results due to its integer arithmetic
as it fails to diminish the zigzags completely.

You might also like