4 Midpoint Circle Drawing Procedure

T. Raghuveera

epgp books

 

 

 

Before going into the Midpoint circle drawing procedure, Lets solve an example problem, to understand how Bresenham’s procedure works for various lines. Consider examples as below.

 

Example Problem -1: (When |m|<=1 and m is +ve)

 

Problem: Scan convert the line between (2, 2) and (10, 5) using Bresenham’s algorithm

 

Sol: Since the line has a slope m=3/8 =0.375 the following set of equations would be valid

 

P0=2∆y-∆x,     ∆y=3,    ∆x=8

P0=6-8=-2

 

Represent first pixel as (X0,Y0) =(2,2).

P0=-2, since, P0 –ve use case (i) i.e. next pixel is (X1,Y1) =(X0+1,Y0)=(3,2) and Compute P1 =P0 +2*3 = -2+6=4, P1 +ve use case (ii)

 

Example Problem -2: (When |m|<=1 and m is -ve)

 

Problem: Scan convert the line between (2, 8) and (10, 5) using Bresenham’s algorithm

Sol:  ∆y = -3, ∆x = 8

 

Since the line has a slope m=-3/8=-0.375 i.e. |m|<1 the same set of equations used for the previous example would be valid.

 

    P0=2|∆y|-|∆x|

|∆y|=3

|∆x|=8

P0=6-8=-2

 

Represent first pixel as (X0,Y0) =(2,8)

P0=-2

use case (i) i.e. next pixel is

(X1,Y1)=(X0+1,Y0)=(3,8) and compute

P1 =P0 +2*3 = -2+6=4

Since P1  is +ve use case (ii) so next pixel to be plotted is (4,7)

P2=4+2×3-2×8 = -6

Since P2 is –ve, the next pixel to be plotted is (5, 7) and continue till we reach the end of line.

 

Note that even if ∆y is –ve, we consider only the magnitude for all computations Observe that while x is increasing in increments of 1 from 3 to 9, while y is decreasing from 8 to 5 as per the algorithm.

 

Conclusion:

  • Important observation while working with negative slopes is that do always compute magnitudes for Δx and Δy i.e. |Δx| and |Δy| and never consider signs.
  • Observe always that Pk should fluctuate about +ve and -ve
  • For Longer lines DDA line drifts away from the true line.
  • Bresenham’s line fluctuates about the theoretical line.
  • Bresenham’s line better approximates the theoretical line i.e., it never deviates from the theoretical line.
  • No floating point calculations are involved.

 

Summary:

  • Outlined the Bresenham’s line drawing procedure
  • Noted the advantages of the procedure over DDA procedure.

 

Midpoint Circle Drawing Procedure:

 

We have started with the first primitive, points, followed by lines, now followed by the third primitive of interest, the circle. A circle is fundamentally symmetric and exhibits octant symmetry. i.e. a circle is symmetric about its octants.

 

If we know a point on any one of the octants the remaining 7 symmetric points can be plotted by interchanging magnitudes of x and y and also signs Lets try to understand what octant symmetry is through the following diagram.

 

 

As shown in the diagram above, divide the circle into 8 parts (each is an octant) using 4 axes. Assume that we know a point say (2, 7) on one of the octants, the remaining 7 symmetric points on the seven octants can be easily plotted without making any computations. If we fold the octants about an axis, the octant exactly overlaps on the neighbouring octant due to symmetry.

 

It is enough that we compute points on one of the octants. The remaining points can be easily plotted without any computations.

 

Assuming the circle is centered at origin and has a radius r units, the algorithm can start with a known point (0, r) and proceed to compute points till the end of the octant is reached. For convenience, we shall chose the first octant i.e. that octant in which the relation x<y is satisfied. We need to compute points on part of the circle shown in the diagram. How do we know where to stop so that the end of the octant is reached? We need to find out the stopping condition for the algorithm. The?? Symbols shown in the diagram represent the last point on the chosen octant at which we should stop. Moreover the point (??) might lie on the axis which satisfies the equation, x=y, that means all points that lie on that axis are like, (2,2) (3,3) and so on. This axis divides the first positive quadrant into two zones or two octants. All points on the upper side of the axis satisfy the relation x<y, while all the points on the lower side of the axis satisfy the relation x>y. That is to fix our stopping condition as we go on computing points, it is just sufficient that we check the relation between x and y, i.e., as long as x<=y we can do our computation, and stop when the relation x<=y is not satisfied by the points. Also observe that in the chosen octant, while we proceed to compute points on the circle boundary, the slope of the circle changes from 0 (positive) to -1 (negative). While x increases, y decreases. Because the circle has slope that is almost flat, we can sample the circle along x-axis at unit steps and compute the corresponding y-values.

 

 

 

  • Start at (0,r)
  • End at (x,y) such that x>=y i.e. whenever x becomes >=y we can stop the algo.
  • Because the shape of the circle in this region is more flat, we can sample it along X-axis at unit intervals, and compute the corresponding y-values.

 

What is the principle behind Midpoint Circle drawing procedure?

 

Equation of circle with centre at origin, and having a radius of r units is given by

x2+y2=r2. We can start with a known point on the circle say (xk,yk) in the chosen octant. Let the next point to be computed be represented as (xk+1,yk+1). Since we are sampling on x-axis at unit x-intervals, it is evident that the next x, xk+1= xk+1.

 

As we know from theory that any point x, y that satisfy the relation

  • x2+y2-r2 <0 is a point that lies inside the circle boundary
  • x2+y2-r2 >0 is a point that lies outside the circle boundary
  • x2+y2-r2 =0 is a point that lies on the circle boundary

For the next x position xk+1, we can choose between two y positions yk or yk-1. Compute midpoint for the two possible pixel locations (xk+1, yk) (xk+1, yk-1) and verify its position relative to the circle boundary. If the midpoint lies inside the circle boundary choose to plot the upper pixel else the lower pixel. The coordinates of the midpoint are for the two possible pixels positions (xk+1, yk) or (xk+1, yk-1) are (?? + ?, ?? − ?/2 )

 

Now by substituting the coordinates of the midpoint, in the circle equation, we can check whether the midpoint lies inside, outside or on the circle boundary. Thus the decision parameter Pk for our derivation is given by

 

i.e., Pk<0, means that midpoint is inside the circle boundary, so the circle boundary is close to the upper pixel, thus choose the upper pixel (xk+1, yk) for plotting, otherwise if Pk>0, the midpoint is outside the circle boundary, so the circle boundary is close to the lower pixel, thus choose the lower pixel (xk+1, yk-1) for plotting, or otherwise if Pk=0, the midpoint lies on the circle boundary, so we can choose between either of upper and lower pixels and so for consistency we can choose the upper pixel, for this case.

 

 

 

 

 

Problem: Find the points on a circle on of its octants with the circle centered at (5,5) and has a radius of 8 units.

Solution: Assume that the circle is centered at origin and proceed to solve. After finding the points add center (5, 5) to each point.

The initial point (x0,y0)=(0,8)

P0 = 1-r = 1-8=-7
(x0,y0) = (0, 8)
P0=-7
P1=-7+2+1=-4 (-ve, case (i))
P2=-4+4+1=1
(+ve, case (ii))
P3=1+6-14+1=-6 (-ve, case (i))

 

Conclusion:

 

Midpoint circle drawing algorithm is more efficient, due to

  • Recursive nature of the algorithm
  • No floating point calculations
  • Accurate and simple
you can view video on Midpoint Circle Drawing Procedure