Friday, April 28, 2017
DDA Circle
DDA Circle
#include<iostream>
#include<math.h>
#include<graphics.h>
using namespace std;
void dda_circle(int xc,int yc,int r);
int main()
{
int xc,yc,r,gd=DETECT,gm;
cout<<" Enter the Center point (xc,yc) :";
cin>>xc>>yc;
cout<<" Enter the Radius :";
cin>>r;
initgraph(&gd,&gm,"");
setcolor(10);
line(0,240,640,240);
line(320,0,320,480);
setcolor(5);
xc = 320 + xc;
yc = 240 - yc;
dda_circle(xc,yc,r);
getch();
closegraph();
return 0;
}
void dda_circle(int xc,int yc,int r)
{
float xc1,xc2,yc1,yc2,eps,sx,sy;
int val,i;
xc1=r;
yc1=0;
sx=xc1;
sy=yc1;
i=0;
do{
val=pow(2,i);
i++;
}while(val<r);
eps = 1/pow(2,i-1);
do{
xc2 = xc1 + yc1*eps;
yc2 = yc1 - eps*xc2;
putpixel(xc+xc2+r,yc-yc2,3);
putpixel(xc+xc2-r,yc-yc2,4);
putpixel(xc+xc2,yc-yc2+r,5);
putpixel(xc+xc2,yc-yc2-r,6);
putpixel(xc+xc2,yc-yc2,15);
xc1=xc2;
yc1=yc2;
}while((yc1-sy)<eps || (sx-xc1)>eps);
}
#include<math.h>
#include<graphics.h>
using namespace std;
void dda_circle(int xc,int yc,int r);
int main()
{
int xc,yc,r,gd=DETECT,gm;
cout<<" Enter the Center point (xc,yc) :";
cin>>xc>>yc;
cout<<" Enter the Radius :";
cin>>r;
initgraph(&gd,&gm,"");
setcolor(10);
line(0,240,640,240);
line(320,0,320,480);
setcolor(5);
xc = 320 + xc;
yc = 240 - yc;
dda_circle(xc,yc,r);
getch();
closegraph();
return 0;
}
void dda_circle(int xc,int yc,int r)
{
float xc1,xc2,yc1,yc2,eps,sx,sy;
int val,i;
xc1=r;
yc1=0;
sx=xc1;
sy=yc1;
i=0;
do{
val=pow(2,i);
i++;
}while(val<r);
eps = 1/pow(2,i-1);
do{
xc2 = xc1 + yc1*eps;
yc2 = yc1 - eps*xc2;
putpixel(xc+xc2+r,yc-yc2,3);
putpixel(xc+xc2-r,yc-yc2,4);
putpixel(xc+xc2,yc-yc2+r,5);
putpixel(xc+xc2,yc-yc2-r,6);
putpixel(xc+xc2,yc-yc2,15);
xc1=xc2;
yc1=yc2;
}while((yc1-sy)<eps || (sx-xc1)>eps);
}
download more info
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment