#include
#include
#include
void main()
{
int n,i,x[10],y[10],a[10],b[10];
float m[10],c[10],xc,yc,r;
int gd=DETECT,gm;
initgraph(&gd,&gm,"..//bgi");
printf("enterd no of sides: ");
scanf("%d",&n);
for(i=0;i
{
printf(" Enter the x and y cordinates: ");
scanf("%d %d",&x[i],&y[i]);
}
x[n]=x[0]; y[n]=y[0];
for(i=0;i
{
line(x[i],y[i],x[i+1],y[i+1]);
delay(500);
}
for(i=0;i
{
a[i]=(x[i]+x[i+1])/2;
b[i]=(y[i]+y[i+1])/2;
}
for(i=0;i
{
if(y[i]!=y[i+1])
{
m[i]=-(float)(x[i]-x[i+1])/(y[i]-y[i+1]);
c[i]=b[i]-m[i]*a[i];
}
else
m[i]=0;
}
i=0;
if(y[i]==y[i+1])
{
xc=a[i];
yc=(float)(m[i+1]*xc+c[i+1]);
}
else if(y[i+1]==y[i+2])
{
xc=a[i+1];
yc=(float)(m[i+2]*xc+c[i+2]);
}
else
{
xc=(c[i+1]-c[i])/(m[i]-m[i+1]);
yc=m[i]*xc+c[i];
}
printf("%f %f %d %d\n",xc,yc,x[1],y[1]);
r=sqrt((xc-x[1])*(xc-x[1])+(yc-y[1])*(yc-y[1]));
putpixel((int)xc,(int)yc,2);
setcolor(3);
printf("%f %f %f",xc,yc,r);
circle((int)xc,(int)yc,r);
setcolor(5);
getch();
}
No comments:
Post a Comment