0% found this document useful (0 votes)
15 views

Midpoint Circle Algorithm

Uploaded by

Suman Bhandari
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Midpoint Circle Algorithm

Uploaded by

Suman Bhandari
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Midpoint Circle Algorithm

• Let us consider a circle centered at origin.


Assume that (x, y) is any point on the circle
we can trivially compute other seven points on
the circle as shown in figure.
• The slope of the circular curve is less than
zero inside the circle, equal to zero on
the circle boundary and greater than zero on
outside the circle.

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.

To apply the midpoint method, we


define a circle function:

fcircle (x, y) = x2 + y2 –r2

The relative position of any point (x, y) can be


determined by checking the sign of
the circle function as: -
i. fcircle (x, y) < 0, the point (x, y) is
inside the circle boundary.
ii. fcircle (x, y) = 0, the point (x, y) is
on the circle boundary.
iii. fcircle (x, y) > 0, the point (x, y)
is outside the circle boundary.

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

Prepared by : Suman Bhandari


Now, subtracting I from II, we
have
Pk+1 – Pk = (xk+1)2 + 2(xk+1) + 1 + (yk+1-1/2)2 –r2 - {(xk+1)2 + (yk-1/2)2 –r2}
= 2(xk+1) +1 + (yk+12 - yk+1 + ¼) –( yk2 – yk + ¼ )
Pk+ 1 = Pk +2(xk+1) + (yk+12 - yk2) - (yk+1 - yk) +1

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

Pk+1 = Pk + 2(xk+1) + [(yk – 1)2 - yk2)] - (yk - 1 - yk) +1


= Pk+2(xk+1) + [(yk 2 - 2yk +1 - yk2)] - (yk-1- yk) + 1
= Pk+2(xk+1) - 2yk +1 +1 + 1
= Pk+2(xk+1) – 2(yk +1)+1

Pk+1 = Pk+2xk+1 – 2yk+1 +1

Initial decision parameter (P0) for circle


The initial decision parameter is obtained by evaluating the circle function at the start
position (x0, y0) = (0, r). Here, the next pixel will either be (1, r) or (1, r-1)
where the midpoint is (1, r -1/2). Thus, the initial decision parameter is given by:
2 2 2
P0 = fcircle (1, r-1/2) = 1 + (r -1/2) – r = 5/4 –r 1–r

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.

Prepared by : Suman Bhandari


Prepared by : Suman Bhandari
Example: Digitize a circle with radius 10.
Solution
Here, the initial decision parameter (P0) =1 – r = 1-10 = - 9
Since, for the Midpoint Circle Algorithm of initial point
(0, r) & center at origin (0, 0) rotating at clockwise
direction, we have
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
Thus,

Prepared by : Suman Bhandari


K Pk Xk+1 Yk+1 ( Xk+1, Yk+1)
0 -9 0+1 = 1 10 (1,10)
1 -9+2*1 +1 = -6 1+1 = 2 10 (2,10)
2 -6+2*2 +1 = -1 2+1 = 3 10 (3,10)
3 -1+2*3+1 = 6 3+1 = 4 10-1 = 9 (4,9)
4 6+ 2* 4 – 2* 9 + 1 = -3 4+1 = 5 9 (5,9)
5 -3+2*5+1 = 8 5+1 = 6 9-1 = 8 (6,8)
6 8 + 2* 6 - 2*8 +1 = 5 6+1 = 7 8-1 = 7 (7,7) (Halt)
for (x<=y) only

Prepared by : Suman Bhandari


Prepared by : Suman Bhandari

You might also like