CIRCLE DRAW ALGORITHMS :
Larry F. Hodges
(modified by Amos Johnson)
The equation for a circle is:
where r is the radius of the circle
So, we can write a simple circle drawing
algorithm by solving the equation
for y at unit x intervals using:
Larry F. Hodges
(modified by Amos Johnson)
21
of
39
Eight way symmetry :
Here circle centred at (0, 0) have eight-way symmetry
(-x, y)
(-y, x)
(y, x)
(-y, -x)
(y, -x)
(-x, -y)
Larry F. Hodges
(modified by Amos Johnson)
(x, y)
(x, -y)
3
Mid Point Circle Algorithm
It uses incremental algorithm for drawing circles the
mid-point circle algorithm
In the mid-point circle algorithm we use eight-way
symmetry so as to calculate the points for the top right
eighth of a circle, and then use symmetry to get the
rest of the points
Larry F. Hodges
(modified by Amos Johnson)
23
of
39
Assume that we have
just plotted point (xk, yk)
The next point is a
choice between (xk+1, yk)
and (xk+1, yk-1)
(xk, yk)
(xk+1, yk)
(xk+1, yk-1)
We would like to choose
the point that is nearest to
the actual circle
Larry F. Hodges
(modified by Amos Johnson)
of
39
Now changing the side of circle give us:
f circ (x, y)
x2
y2
r2
The equation evaluates as follows:
0, if (x, y) is inside the circle boundary
fcirc (x, y)
0, if (x, y) is on the circle boundary
0, if (x, y) is outside the circle boundary
By evaluating this function at the midpoint
between the candidate pixels we can
make our decision
Larry F. Hodges
(modified by Amos Johnson)
39
Assuming we have just plotted the pixel at
(xk,yk) so we need to choose between
(xk+1,yk) and (xk+1,yk-1)
Our decision variable can be defined as:
pk
fcirc (xk
(x k 1)2
(y
1 )
2
1,
yk
k
1 2 )2
2
If pk < 0 the midpoint is inside
the circle and
the pixel at yk is closer to the circle
Otherwise the midpoint is outside and yk-1
is
closer
Larry F. Hodges
(modified by Amos Johnson)
39
The first decision variable is given
1 )
as:
p0 fcirc (1,
2
1 )2 2
r
2
1 (r
5
Then if pk < 0 then the next decision variable
is given as:
pk
pk
2xk
If pk > 0 then the decision variable is:
pk
Larry F. Hodges
(modified by Amos Johnson)
pk
2xk
1 2 yk 1
8
39
MID-POINT CIRCLE ALGORITHM
Input radius r and circle centre (xc, yc), then
set the coordinates for the first point on the
circumference of a circle centred on the origin
as:
(x , y ) (0, r)
0
Calculate the initial value of the decision parameter as:
5
4
p0
Starting with k = 0 at each position xk, perform the
following test. If pk < 0, the next point along the circle
centred on (0, 0) is (xk+1, yk) and:
pk
Larry F. Hodges
(modified by Amos Johnson)
pk
2xk
1
9
29
of
39
Otherwise the next point along the circle is (xk+1, yk-1)
and:
pk
pk
2xk
1 2 yk
4.
5.
Determine symmetry points in the other seven octants
Move each calculated pixel position (x, y) onto the
circular path centred at (xc, yc) to plot the coordinate
values:
6.
Repeat steps 3 to 5 until x >= y
xc
Larry F. Hodges
(modified by Amos Johnson)
yc
10