Java Applets Centre
Midpoint Algorithm (Circular Arc)


Description
This applet demonstrates the working of the midpoint algorithm in drawing a circular arc where the slope of the tangent is less than 1. The pixels in this region are represeted by circular regions.
Select any blue-colored pixel on the left hand side of the window by clicking on it. The selected point defines the radius of the arc. A circular arc from this point is drawn using the midpoint algorithm. The candidate pixels at each stage are shown in yellow color.


Code (Midpoint Algorithm: Arc)

void arc(double rad){
  int x2=(int)(rad*0.7071);
  int p=(int)(1.25-rad);
  int y=(int)rad;
  for (int x=0; x <=x2; x++) {
   setPixel(x, y);
   if(p > 0) {
    y--;
    p+ = 2*(x-y)+5;
   }
   else
    p+ = 2*x+3;
 }
}

Computer Graphics
Java Applets Centre


R. Mukundan
Department of Computer Science
University of Canterbury
Private Bag 4800, Christchurch
New Zealand.