Circle Generation Algorithm
Circle Generation Algorithm
http://www.tutorialspoint.com/computer_graphics/circle_generation_algorithm.htm
Copyright tutorialspoint.com
Drawing a circle on the screen is a little complex than drawing a line. There are two popular
algorithms for generating a circle Bresenhams Algorithm and Midpoint Circle Algorithm.
These algorithms are based on the idea of determining the subsequent points required to draw the
circle. Let us discuss the algorithms in detail
The equation of circle is X 2 + Y2 = r2 , where r is radius.
Bresenhams Algorithm
We cannot display a continuous arc on the raster display. Instead, we have to choose the nearest
pixel position to complete the arc.
From the following illustration, you can see that we have put the pixel at X, Y location and now
need to decide where to put the next pixel at N X + 1, Y or at S X + 1, Y 1.
Algorithm
Step 1 Get the coordinates of the center of the circle and radius, and store them in x, y, and R
respectively. Set P=0 and Q=R.
Step 2 Set decision parameter D = 3 2R.
Step 3 Repeat through step-8 while X < Y.
Step 4 Call Draw Circle X, Y, P, Q.
Step 5 Increment the value of P.
Step 6 If D < 0 then D = D + 4x + 6.
Step 7 Else Set Y = Y + 1, D = D + 4X Y + 10.
Step 8 Call Draw Circle X, Y, P, Q.
Draw Circle Method(X, Y, P, Q).
Call
Call
Call
Call
Call
Call
Call
Call
Putpixel
Putpixel
Putpixel
Putpixel
Putpixel
Putpixel
Putpixel
Putpixel
(X
(X
(X
(X
(X
(X
(X
(X
+
+
+
+
-
P,
P,
P,
P,
Q,
Q,
Q,
Q,
Y
Y
Y
Y
Y
Y
Y
Y
+
+
+
+
-
Q).
Q).
Q).
Q).
X).
X).
X).
X).
Y = Y + YC