used to determine the points needed for drawing circle.
Similar to Bresenham's approach.
Also known as Bresenham's circle algorithm
difference between Bresenham's circle algorithm and midpoint circle algorithm:
- bresenham's results in a much more smother circle, compared to midpoint circle algorithm.
- in midpoint decision parameter depends on previous decision parameter and corresponding pixels, whereas in bresenham's decision parameter only depends on previous decision parameter.
//Bresenham Line Algorithm
#include
#include
#include
void main()
{
clrscr();
int dx,dy,x,y,p,x1,y1,x2,y2;
int gd=DETECT,gm;
cout<<"Enter the 1st coordinates: "; cin>>x1>>y1;
cout<<"Enter the 2nd coordinates:"; cin>>x2>>y2;
dx = x2-x1;
dy = y2-y1;
p=2*dy-dx;
x=x1;
y=y1;
initgraph(&gd, &gm, "c:\\tc\\bgi");
putpixel(x,y,RED);
while(x<=x2)
{
if(p<0)
{
x=x+1;
y=y;
p = p+2*(dy);
}
else
{
x=x+1;
y=y+1;
p=p+2*(dy-dx);
}
putpixel(x,y,BLUE);
}
getch();
closegraph();
}
No comments:
Post a Comment