新学期第一个算法大作业就好坑爹。。。
要计算三角形外接圆。。。做模板用吧
# include
# include
double X1,Y1,X2,Y2,X3,Y3,x4,y4,length1,length2,length3;
int a;
void myprintf(double x1,double y1,double x2,double y2,double x3,double y3)
{
char ch;
printf("输入第一个点的坐标值,横纵坐标用逗号隔开(如(0,0)):");
while(scanf("(%lf,%lf)",&X1,&Y1)!=2)
{
while((ch=getchar())!='\n')
{
continue;
}
printf("输入有误,请重新输入第一个点的坐标值,横纵坐标用逗号隔开(如(0,0)):");
}
while((ch=getchar())!='\n')
{
continue;
}
printf("输入第二个点的坐标值,横纵坐标用逗号隔开(如(0,0)):");
while(scanf("(%lf,%lf)",&X2,&Y2)!=2)
{
while((ch=getchar())!='\n')
{
continue;
}
printf("输入有误,请重新输入第二个点的坐标值,横纵坐标用逗号隔开(如(0,0)):");
}
while((ch=getchar())!='\n')
{
continue;
}
printf("输入第三个点的坐标值,横纵坐标用逗号隔开(如(0,0)):");
while(scanf("(%lf,%lf)",&X3,&Y3)!=2)
{
while((ch=getchar())!='\n')
{
continue;
}
printf("输入有误,请重新输入第三个点的坐标值,横纵坐标用逗号隔开(如(0,0)):");
}
while((ch=getchar())!='\n')
{
continue;
}
}
void main()
{
myprintf(X1,Y2,X2,Y2,X3,Y3);
length1=sqrt(pow(X1-X2,2)+pow(Y1-Y2,2));
length2=sqrt(pow(X1-X3,2)+pow(Y1-Y3,2));
length3=sqrt(pow(X2-X3,2)+pow(Y2-Y3,2));
while((length1>=length2+length3)||(length2>=length1+length3)||length3>=length1+length2)
{
printf("输入的三个点不能构成三角形,请重新输入\n");
myprintf(X1,Y2,X2,Y2,X3,Y3);
length1=sqrt(pow(X1-X2,2)+pow(Y1-Y2,2));
length2=sqrt(pow(X1-X3,2)+pow(Y1-Y3,2));
length3=sqrt(pow(X2-X3,2)+pow(Y2-Y3,2));
}
x4=(pow(X2,2)*Y1-pow(X3,2)*Y1-pow(X1,2)*Y2+pow(X3,2)*Y2-pow(Y1,2)*Y2+pow(Y2,2)*Y1+pow(X1,2)*Y3-pow(X2,2)*Y3+pow(Y1,2)*Y3-pow(Y2,2)*Y3-pow(Y3,2)*Y1+pow(Y3,2)*Y2)/(2*(X2*Y1-X3*Y1-X1*Y2+X3*Y2+X1*Y3-X2*Y3));
y4=-(-pow(X1,2)*X2+pow(X2,2)*X1+pow(X1,2)*X3-pow(X2,2)*X3-pow(X3,2)*X1+pow(X3,2)*X2-pow(Y1,2)*X2+pow(Y1,2)*X3+pow(Y2,2)*X1-pow(Y2,2)*X3-pow(Y3,2)*X1+pow(X3,2)*X2)/(2*(X2*Y1-X3*Y1-X1*Y2+X3*Y2+X1*Y3-X2*Y3));
printf("此三角形外心坐标为(%lf,%lf)\n",x4,y4);
}