Pages

Thursday, February 17, 2011

BRESENHAM'S CIRCLE ALGORITHM

This algorithm will dram an arc from 90 degree angle to 45 degree angle.... after that to construct the whole circle we have to take its mirror image in all 8 quardrants..... the other algorithm for drawing a circle is MID POINT ALGORITHM....

#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<process.h>
#include<math.h>
void main()
{
int gdriver=DETECT,gmode,errorcode;
initgraph(&gdriver,&gmode,"c:\\tc\\bgi ");
errorcode=graphresult();
if(errorcode!=grOk)
{
cout<<"graphics error"<<grapherrormsg(errorcode)<<endl; cout<<"press any key to start"; getch(); exit(1); } clrscr(); int r,x,d,y; cout<<"enter the radius of the circle"; cin>>r;
x=0; y=r; d=3-(2*r);
while(x<=y)
{
putpixel(x,y,RED);
if(d<0)
{
d=d+4*x+6;
}
else
{

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

No comments:

Post a Comment