Midpoint Circle Algorithm
Midpoint Circle Algorithm
We can generate all pixel positions around a circle by calculating only the points within
the first octants & positions in the other seven octants are obtained by symmetry.
• Here, we have to calculate all the pixel
position from (0, r) up to both the co-ordinate
either equal or x-coordinate is greater than
that of the y-coordinate.
Suppose, (xk, yk) is the pixel plotted, then the next pixel (xk+1, yk+1) will be either (xk+1, yk) or
(xk+1, yk-1) as shown in figure.
Here, the mid-point (m) = (xk+1, yk-1/2).
Thus, our decision parameter
(Pk) = fcircle (xk+1, yk-1/2) = (xk+1)2 + (yk-1/2)2 –r2 …………………………….i
is the circle function evaluated at midpoint.
Also, the successive decision parameters are obtained using incremental calculations.
We obtain a recursive expression for the next decision parameter by evaluation the circle
function at sampling position xk+1+1 = xk+2. Thus, the next pixel to plot will either be (xk+1+1,
yk+1) or (xk+1+1, yk+1-1).
Also, the midpoint here is (xk+1+1, yk+1-1/2) and thus, our decision parameter
(Pk+1) = fcircle (xk+1+1, yk+1-1/2)
Pk+1 = (xk+1+1)2 + (yk+1-1/2)2 –r2
Pk+1 = {(xk+1) +1}2 + (yk+1-1/2)2 –r2
2 2 2
Pk+1 = (xk+1) + 2(xk+1) + 1 + (yk+1-1/2) –r ……………………….ii
If Pk < 0, the midpoint is inside the circle and the pixel on the scan line yk closer to the
circle boundary. Otherwise, the midpoint is outside or on the circle boundary, and we select the
pixel on scan line yk-1.
Case – I: Pk < 0
xk+1 = xk +1
yk+1 = yk
Pk+1 = Pk + 2(xk+1) + 1
Pk+1 = Pk + 2xk+1 + 1
Case – I: Pk 0
xk+1 = xk +1
yk+1 = yk - 1
Thus,
P0 =1 – r
Conclusion
Calculate the initial decision parameter (P0) =1 – r
If P < 0
Plot (xk +1, yk )
Pk+1 = Pk + 2xk+1 + 1
Else P 0
Plot (xk +1, yk - 1)
Pk+1 = Pk+2xk+1 – 2yk+1 +1
Note : If the center of the circle is not at origin then first calculate the octant points of the circle
in the same way as the center at origin & then add the given circle center on each calculated
pixels.