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 //used for delay function
void plot (float, float, float, float);
int gd=DETECT, gm;
initgraph(&gd, &gm, “c:\\tc\\bgi”);
float xc, yc, x, y, r, p;
plot(xc, yc, x,y);
plot(xc, yc, x, y);
void plot(float xc, float yc, float x, float y)
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);