0% found this document useful (0 votes)
14 views5 pages

Circle

Dsa notes

Uploaded by

markshaikh50
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views5 pages

Circle

Dsa notes

Uploaded by

markshaikh50
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Midpoint Circle Drawing Algorithm

What is a circle?

A circle is defined as a set of points that all are the same distance from a common point known as the center
and the distance from the center of the circle to any point on its circumference is called a radius.

It is an eight-way symmetric figure which can be divided into four quadrants and each quadrant has two
octants. This symmetry helps in the implementation of any circle drawing algorithm.

The midpoint circle drawing algorithm helps us to calculate the complete perimeter points of a circle for
the first octant. We can quickly find and calculate the points of other octants with the help of the first octant
points. The remaining points are the mirror reflection of the first octant points.
Let us assume we have a point a (p, q) on the boundary of the circle and with r radius satisfying the
equation fc (p, q) = 0

As we know the equation of the circle is –


fc (p, q) = p2 + q2 = r2 …………………………… (1)
If
fc (p, q) < 0
then
The point is inside the circle boundary.
If
fc (p, q) = 0
then
The point is on the circle boundary.
If
fc (p, q) > 0
then
The point is outside the circle boundary.
In the figure, we calculate the mid-point (m). The midpoint appears between qk and qk -1.
The current position of the pixel = pk +1
The next position of the pixel = (pk +1, qk) and (pk +1, qk - 1)
Now, we will calculate the decision parameter (dk)
dk = (pk +1, qk – 1/2)
Now, we replace all the values with equation (1)
dk = (pk +1)2 + (qk – 1/2)2 – r2 …………………………………… (2)

Now, there should be two conditions.


Condition 1: If
dk is negative
then
The midpoint (m) is inside the circle boundary
Condition 2: If
dk is positive
then
The midpoint (m) is outside the circle boundary
Now, we find the next point of x coordinates. Then,
Pk+1 +1 = Pk+2
Now, we replace all the value of equation (2) with (k+1). We get-
dk+1 = (pk+1 +1)2 + (qk+1 – 1/2)2 – r2 ……………………………. (3)
Now, we will find the difference between
dk+1 – dk = {(pk+1 +1)2 + (qk+1 – 1/2)2 – r2} – {(pk +1)2 + (qk – 1/2)2 – r2}
= dk +(2pk +1) + (qk+12 – qk2) – (qk+1 – qk) +1 …………………… (4)
Here, If
dk is negative then dk+1
then
2pk+1 +1
Otherwise
2pk+1 +1 – 2qk+1

Now, the next coordinate for x and y points


2pk+1 = 2pk +2
2qk+1 = 2qk –2

Now, the initial decision parameter (d0) at the position (p, q) = (0, r)
We put (0, r) in circle equation and we get-
d0 = (1, r – 1/2)
= (1 + (r –1/2)2 –r2)
= 5/4 –r
We only take integer value = 1 – r

Algorithm of Midpoint Circle Drawing


Step 1: Start.

Step 2: First, we allot the center coordinates (p0, q0) as follows-


P0 = 0
q0 =r
Step 3: Now, we calculate the initial decision parameter d0 -
d0 = 1 – r
Step 4: Assume, the starting coordinates = (pk, qk)
The next coordinates will be (pk+1, qk+1)
Now, we find the next point of the first octant according to the value of the decision parameter (dk).

Step 5: Now, we follow two cases-

Case 1: If
dk < 0
then
pk+1 =pk + 1
qk+1 =qk
dk+1 = dk + 2 pk+1 + 1
Case 2: If
dk >= 0
then
pk+1 =pk + 1
qk+1 =qk –1
dk+1 = dk - 2 (qk+1 + 2 pk+1)+ 1

Step 6: If the center coordinate point (p0, q0) is not at the origin (0, 0) then we will draw the points as
follow-
For x coordinate = xc + p0
For y coordinate = yc + q0 {xc and yc contains the current value of x and y coordinate}
Step 7: We repeat step 5 and 6 until we get x>=y.
Step 8: Stop.

You might also like