Mid Point Circle Generation Algorithm
Mid Point Circle Generation Algorithm
The Mid-point Circle Generation Algorithm works by determining the points needed for
rasterizing it. It is efficient because it calculates the points present in the first octant of
the circle and uses the circle's symmetry to generate the remaining points for the other
seven octants.
In this chapter, we will explain the basics of the mid-point circle generation algorithm
and go through a detailed example. We will also cover its step-by-step implementation
for a better understanding.
Symmetry of Circles
As we have seen in the last algorithm also the circle generation has been done with the
idea of symmetry. We generate for only 45 and rest can be easily calculated with
changing the coordinate values, since a circle is symmetric about its center.
For a circle with a center at (0,0) and radius r, the equation of the circle is −
2 2 2
x + y = r
Given a point P(x, y) on the circle, the decision to plot the next point depends on
whether the midpoint between two possible pixels lies inside or outside the circle.
Page 2 of 6
Here, P and Q both points are inside the circle, whereas the point R is outside of the
circle.
The Algorithm
Start with an initial point − The first point to be plotted is (r, 0), which lies on
the positive X-axis.
P1 = 1 − r
Iterate through points in the first octant − For each subsequent point, we
check whether the next pixel is above or below the circle or not. The next pixel is
either at (x, y + 1) or (x − 1, y + 1)
If the decision parameter is less than or equal to zero, the midpoint is inside
the circle. In this case, the next pixel is (x, y + 1).
If the decision parameter is greater than zero, the midpoint is outside the
circle. The next pixel is (x − 1, y + 1) .
Update the decision parameter − For each new pixel, update the decision
parameter depending on which pixel was chosen.
P k+1 = P k + 2y k + 1
P k+1 = P k + 2y k − 2x k + 1
Initial decision parameter − Using the formula, the initial decision parameter P1 is −
P1 = 1 − r = 1 − 3 = −2
First iteration − For the first iteration, we start with x = 3 and y = 0. Since P1 = − 2
(which is less than 0), the next point is (3, 1). The new decision parameter is −
P2 = P 1 + 2y 1 + 1 = −2 + 2(0) + 1
The points at this stage are: (3, 0), (−3, 0), (0, 3), and (0, −3). Using symmetry, we
also plot (3, 1), (−3, 1), (3, −1), and (−3, −1).
P3 = P 2 + 2y 2 + 1 = −1 + 2(1) + 1 = 2
The points at this stage are: (3, 2), (3,2), (3, 2), and (3, 2)
P4 = P 3 + 2y 3 − 2x 3 + 1 = 2 + 2(2) − 2(3) + 1 = 3
The points at this stage are: (2, 3), (2, 3), (2, 3), and (2, 3)
Final iteration − For the final iteration, with x = 2 and y = 3, since P4 = 3 (which is
greater than 0), the next point is (1, 3). The decision parameter is updated, but since x
is now smaller than y, the algorithm stops.
The points at this stage are: (1, 3), (1, 3), (1, 3), and (1,3)
Full Set of Points − After completing all iterations, we have the following points for the
circle with a radius of 3 and center at (0,0) −
Page 4 of 6
(3, 0), (3, 0), (0, 3), (0, 3), (3, 1), (3, 1), (3, 1), (3, 1), (3, 2), (3, 2), (3, 2), (3, 2), (2,
3), (2, 3), (2, 3), (2, 3), (1, 3), (1, 3), (1, 3), (1, 3).
Conclusion
In this chapter, we explained the Mid-point circle generation algorithm in detail. We
started the chapter with a brief discussion on the symmetry of circles, which forms the
basis of the algorithm. Then, we outlined the steps of the algorithm, explaining how the
decision parameter helps in determining the next point to plot. Finally, we worked
through an example with a radius of 3 to explain the algorithm in action.
TOP TUTORIALS
Python Tutorial
Java Tutorial
C++ Tutorial
C Programming Tutorial
C# Tutorial
PHP Tutorial
R Tutorial
HTML Tutorial
CSS Tutorial
JavaScript Tutorial