COMPUTER GRAPHICS - Bresenham’s Circle and Mid-point Circle Drawing Algorithm

 Bresenham’s Circle Drawing Algorithm

Step 1

        Accept circle center and radius (100, 100) and radius 50 as input.

Step 2

To set up initial parameters.

x = 0, y = r ( y = 50 ), di = 3 - 2 * r ( di = -97).

Step 3

Move the value of x from x = 0 to x = y by unit step.

Step 4

       Display circle pixels using eight way symmetry.

( Write 8 putpixel commands here )

Step 5

        if (di <= 0)

then select pixel at position ( xi + 1, yi )

di = di + 4 * xi + 6.

else

 Select pixel at position ( xi + 1, yi - 1)

 di = di + 4 * xi - 4 * yi + 10.

y = y - 1.

Step 6

        Repeat the procedure through Step 3.

Step 7

End.


Mid - point Circle Drawing Algorithm

Step 1

        Accept circle center and radius (100, 100) and radius 50 as input.

Step 2

To set up initial parameters.

x = 0, y = r ( y = 50 ), di = ( 5 / 4 ) - r ( di = - 49 ).

Step 3

Move the value of x from x = 0 to x = y by unit step.

Step 4

       Display circle pixels using eight way symmetry.

( Write 8 putpixel commands here )

Step 5

        if (di <= 0)

then select pixel at position ( xi + 1, yi )

di = di + 2 * xi + 3.

else

 Select pixel at position ( xi + 1, yi - 1)

 di = di + 2 * xi - 2 * yi + 5.

y = y - 1.

Step 6

        Repeat the procedure through Step 3.

Step 7

End.


Code : 

1)BRESENHAM’S CIRCLE DRAWING ALGORITHM:-

#include<stdio.h>;

#include<conio.h>;

#include<graphics.h>;

#include<math.h>;

void EightWaySymmetricPlot(int xc,int yc,int x,int y)

{

putpixel(x+xc,y+yc,RED);

putpixel(x+xc,-y+yc,YELLOW);

putpixel(-x+xc,-y+yc,GREEN);

putpixel(-x+xc,y+yc,YELLOW);

putpixel(y+xc,x+yc,12);

putpixel(y+xc,-x+yc,14);

putpixel(-y+xc,-x+yc,15);

putpixel(-y+xc,x+yc,6);

}

void BresenhamCircle(int xc,int yc,int r)

{

int x=0;

int y=r;

int d=3-(2*r);

EightWaySymmetricPlot(xc,yc,x,y);

while(x<y)

{

if(d<=0)

{

d=d+(4*x)+6;

}

else

{

d=d+(4*x)-(4*y)+10;

y=y-1;

}

x=x+1;

EightWaySymmetricPlot(xc,yc,x,y);

}

}

int main()

{

int xc,yc,r,gd= DETECT, gm;

initgraph(&gd,&gm,”C:\\TURBOC3\\BGI”);

printf(“Enter the values of xc and yc :”);

scanf(“%d%d”,&xc,&yc);

printf(“Enter the value of radius :”);

scanf(“%d”&r);

BresenhamCircle(xc,yc,r);

getch();

closegraph();

return 0;

}

closegraph();

return 0;

}


2)MIDPOINT CIRCLE ALGORITHM:-

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

void pixel(int xc,int yc,int x,int y);

int main()

{

int gd=DETECT,gm;

int xc,yc,r,x,y,p;

detectgraph(&gd,&gm);

initgraph(&gd,&gm,”C:\\TurboC3\\BGI”);

printf(“Enter centre of circle :”);

scanf(“%d%d”,&xc,&yc);

printf(“Enter radius of circle :”);

scanf(“%d”&r);

x=0;

y=r;

p=1-r;

pixel(xc,yc,x,y);

while(x<y)

{

if(p<0)

{

x++;

p=p+2*x+1;

}

else

{

x++;

y--;

p=p+2*(x-y)+1;

}

pixel(xc,yc,x,y);

}

getch();

closegraph();

return 0;

}

void pixel(int xc,int yc,int x,int y)

{

putpixel(xc+x,yc+y,WHITE);

putpixel(xc+x,yc-y,WHITE);

putpixel(xc-x,yc+y,WHITE);

putpixel(xc-x,yc-y,WHITE);

putpixel(xc+y,yc+x,WHITE);

putpixel(xc+y,yc-x,WHITE);

putpixel(xc-y,yc+x,WHITE);

putpixel(xc-y,yc-x,WHITE);

}


Output : 

1) OUTPUT OF BRESENHAM’S CIRCLE ALGORITHM :


2)OUTPUT OF MIDPOINT CIRCLE ALGORITHM :


Conclusion:

The Midpoint circle drawing algorithm is an algorithm used to determine the points needed for rasterizing a circle.

We use the midpoint algorithm to calculate all the perimeter points of the circle in the first octant and then print them along with their mirror points in the other octants. 

 

Question of Curiosity

Q.1] Plot the circle points r=50 (xc,yc)=(100,100) Midpoint Circle Drawing Algorithm?

Answer :

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

void pixel(int xc,int yc,int x,int y);

int main()

{

int gd=DETECT,gm,xc,yc,r,x,y,p;

detectgraph(&gd,&gm);

initgraph(&gd,&gm,”C:\\TurboC3\\BGI”);

xc=100;

yc=100;

r=50;

x=0;

y=r;

p=1-r;

pixel(xc,yc,x,y);

while(x<y)

{

if(p<0)

{

x++;

p=p+2*x+1;

}

else

{

x++;

y--;

p=p+2*(x-y)+1;

}

pixel(xc,yc,x,y);

}


getch();

closegraph();

return 0;

}

void pixel(int xc,int yc,int x,int y)

{

putpixel(xc+x,yc+y,WHITE);

putpixel(xc+x,yc-y,WHITE);

putpixel(xc-x,yc+y,WHITE);

putpixel(xc-x,yc-y,WHITE);

putpixel(xc+y,yc+x,WHITE);

putpixel(xc+y,yc-x,WHITE);

putpixel(xc-y,yc+x,WHITE);

putpixel(xc-y,yc-x,WHITE);

}


Q.2] Which are different types of Circle drawing algorithms?

Answer : 

The algorithms to draw the Circle are :

  • Polynomial Method
  • Trigonometric Method
  • Bresenham’s Circle Drawing Algorithm
  • Midpoint Circle Drawing Algorithm
  • DDA Circle Drawing Algorithm



Q.3] Which are Advantages and Disadvantages of Midpoint Circle drawing algorithm?

Answer : 

ADVANTAGES OF MIDPOINT CIRCLE DRAWING ALGORITHM:-

  1. The entire algorithm is based on the simple equation of circle X2 + Y2 = R2.
  2. It is easy to implement from the programmer’s perspective.
  3. This algorithm is used to generate curves on raster displays.


DISADVANTAGES OF MIDPOINT CIRCLE DRAWING ALGORITHM:-

  1. It takes too much time to compile.
  2. This is not much accurate.
  3. Distance between the pixels is not equal so we won’t get smooth circle.
  4. This algorithm is not suitable for complex and high graphics images.


Q.4]Explain 8-way Symmetry of circle?

Answer : 

  1. A Circle is an eight-way symmetric figure.
  2. The shape of circle is the same in all quadrants. In each quadrant, thereare two octants. 
  3. If the calculation of the point of one octant is done, then the other seven points can be calculated easily by using the concept of eight-way symmetry.
  4. For every point (x,y) 8 points can be plotted.
  5. These are (x,y),(y,x),(-y,x),(-x,y),(-x,-y),(-y,-x),(y,-x),(x,-y).
  6. For any point (x+a,y+b),points (x+a,y+b) and (y+a,x+b) also lie on the same circle.
  7. So, it is sufficient to compute only 1/8 of a circle and all the other points can be computed from it.

Comments