Midpoint Circle Algorithm
Mid point algorithm is very similar to
Bresenham’s approach. It is based on the
following function for testing the spatial
relationship between an arbitrary point(x,y)
and a circle of radius centered at the origin:
                        < 0 (x,y) inside circle
f(x,y) = x2 + y2 – r2 = 0 (x,y) on the circle
                        > 0 (x,y) outside
   circle`
Now consider the coordinates of the point
halfway between pixel T & S (xi + 1, yi – ½)
This is called the midpoint and we use it to
define a decision parameter:
           pi = f( xi +1, yi – ½)
              = (xi + 1)2 + (yi – ½)2 – r2
If pi is –ve , the midpoint is inside the circle,
then we choose pixel T. If pi is +ve, the
midpoint is outside the circle, & we choose S.
Similarly, the decision parameter for the next
step is:
pi+1 = (xi+1 + 1)2 + (yi+1 – ½)2 – r2
Since x i+1 = xi + 1
       pi+1 - pi = [(xi + 1)+ 1]2 – (xi + 1)2
                   + (y i+1 – ½)2 – (yi – ½)2
Hence
     pi+1 = pi + 2(xi + 1) + 1 + (y i+12 – yi2)
                – (y i+1 – yi)
If pixel T is chosen (meaning pi < 0), we
   have yi+1 = yi.
If pixel S is chosen (meaning pi > 0), we
   have yi+1 = yi – 1. Thus,
   pi+1= pi + 2(xi + 1) +1                if pi<0
           pi + 2(xi + 1) +1 – 2(yi – 1) if pi>0
In terms of (xi, yi), we have
    pi+1= pi + 2xi + 3             if pi<0
           pi + 2(xi - yi ) + 5      if pi>0
Finally, we compute the initial value for the
decision parameter using the original
definition of pi and (0,r):
    pi = (0 + 1)2 + (r – ½)2 – r2 = 5/4 – r
One can see that this is not really integer
computation. However, when r is an integer
we can simply set p1= 1 – r. The error of
being ¼ less than the precise value does not
prevent p1 from getting the appropriate sign.
It does not affect the rest of the scan
conversion process, because the decision
variable is only updated with integer increment
in subsequent steps.
Algorithm:
The following is a description of this midpoint
circle algorithm that generates the pixel
coordinates in the 90˚ to 45 ˚ octant:
    int x = 0, y = r, p = 1-r
    while (x <=y)
      { setpixel(x,y);
       if (p < 0)
       p = p + 2x + 3
else
   {
     p = p + 2(x – y) + 5
    y- -
    }
   x++
 }

Midpoint circle algo

  • 1.
    Midpoint Circle Algorithm Midpoint algorithm is very similar to Bresenham’s approach. It is based on the following function for testing the spatial relationship between an arbitrary point(x,y) and a circle of radius centered at the origin: < 0 (x,y) inside circle f(x,y) = x2 + y2 – r2 = 0 (x,y) on the circle > 0 (x,y) outside circle`
  • 2.
    Now consider thecoordinates of the point halfway between pixel T & S (xi + 1, yi – ½) This is called the midpoint and we use it to define a decision parameter: pi = f( xi +1, yi – ½) = (xi + 1)2 + (yi – ½)2 – r2 If pi is –ve , the midpoint is inside the circle, then we choose pixel T. If pi is +ve, the midpoint is outside the circle, & we choose S.
  • 3.
    Similarly, the decisionparameter for the next step is: pi+1 = (xi+1 + 1)2 + (yi+1 – ½)2 – r2 Since x i+1 = xi + 1 pi+1 - pi = [(xi + 1)+ 1]2 – (xi + 1)2 + (y i+1 – ½)2 – (yi – ½)2 Hence pi+1 = pi + 2(xi + 1) + 1 + (y i+12 – yi2) – (y i+1 – yi)
  • 4.
    If pixel Tis chosen (meaning pi < 0), we have yi+1 = yi. If pixel S is chosen (meaning pi > 0), we have yi+1 = yi – 1. Thus, pi+1= pi + 2(xi + 1) +1 if pi<0 pi + 2(xi + 1) +1 – 2(yi – 1) if pi>0 In terms of (xi, yi), we have pi+1= pi + 2xi + 3 if pi<0 pi + 2(xi - yi ) + 5 if pi>0
  • 5.
    Finally, we computethe initial value for the decision parameter using the original definition of pi and (0,r): pi = (0 + 1)2 + (r – ½)2 – r2 = 5/4 – r One can see that this is not really integer computation. However, when r is an integer we can simply set p1= 1 – r. The error of being ¼ less than the precise value does not prevent p1 from getting the appropriate sign.
  • 6.
    It does notaffect the rest of the scan conversion process, because the decision variable is only updated with integer increment in subsequent steps.
  • 7.
    Algorithm: The following isa description of this midpoint circle algorithm that generates the pixel coordinates in the 90˚ to 45 ˚ octant: int x = 0, y = r, p = 1-r while (x <=y) { setpixel(x,y); if (p < 0) p = p + 2x + 3
  • 8.
    else { p = p + 2(x – y) + 5 y- - } x++ }