# Write a program (WAP) to draw a circle using Mid-point Algorithm

Although Bresenham’s algorithm is based upon integral operations only and is much faster than other algorithms, yet there is one drawback of this algorithm. This method is not uniformly applicable to all sorts of conics. For eg, for the ellipse drawing procedure, we need to treat two different regions in the first quadrant differently. This complication can be avoided by the midpoint method.
Mid-Point Circle Algorithm:
The following program written in C++ programming language uses circular symmetry of eight octants of the circle. Also delay in corresponding functions are used. Note the use of header file dos.h for delay.
// WAP to draw a circle using mid-point circle algorithm.
#include
#include
#include
#include
#include //used for delay function
void plot (float, float, float, float);
void main()
{
int gd=DETECT, gm;
initgraph(&gd, &gm, “c:\\tc\\bgi”);
float xc, yc, x, y, r, p;
cout<>xc>>yc;
x=0;y=r;
p=(1-r);
while(x
{
if(p
{
x++;
plot(xc, yc, x,y);
p=p+2*x+1;
}
else
{
x++;
y–;
plot(xc, yc, x, y);
p=p+2*x-2*y+1;
}
}
getch();
closegraph();
}
void plot(float xc, float yc, float x, float y)
{
// cleardevice();
putpixel(xc+x, yc+y, RED);
putpixel(xc-x, yc+y, RED);
putpixel(xc+x, yc-y, RED);
putpixel(xc-x, yc-y, RED);
putpixel(xc+y, yc+x, RED);
putpixel(xc-y, yc+x, RED);
putpixel(xc+y, yc-x, RED);
putpixel(xc-y, yc-x, RED);
delay(20);
}