Midpoint Circle Algorithm

Posted: November 6, 2011 in Computer Graphics

Implementation

#include<iostream.h>

#include<conio.h>

#include<graphics.h>

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

{

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

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

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

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

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

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

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

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

}

void main()

{

clrscr();

int gdriver=DETECT,gmode;

initgraph(&gdriver,&gmode,”c:/tc/bgi”);

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

cout<<“\n enter the cooridinates of center “;

cin>>xc>>yc;

cout<<“\n enter radius “;

cin>>r;

y=r;

p=1-r;

plot(xc,yc,x,y);

while(x<y)

{

x++;

if(p<0)

p+=2*x+1;

else

{

y–;

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

}

plot(xc,yc,x,y);

}

getch();

}

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s