编写程序,输入平面上3个点,求过这3个点的圆的圆心和半径
答案:1 悬赏:20 手机版
解决时间 2021-04-23 23:29
- 提问者网友:轮囘Li巡影
- 2021-04-23 02:42
编写程序,输入平面上3个点,求过这3个点的圆的圆心和半径
最佳答案
- 五星知识达人网友:你哪知我潦倒为你
- 2021-04-23 03:59
#include
#include
int main()
{
int x1,y1,x3,y3;
double a,b,c,d,e,f;
double r,k1,k2,x,y,x2,y2;
cout<<"请输入x1,y1,x2,y2,x3,y3"<
cin>>x1>>y1>>x2>>y2>>x3>>y3;
k1=1,k2=2;
if((y1==y2)&&(y2==y3))
{
cout<<"三点不构成圆!"<
return 0;
}
if((y1!=y2)&&(y2!=y3))
{
k1=(x2-x1)/(y2-y1);
k2=(x3-x2)/(y3-y2);
}
if(k1==k2)
{
cout<<"三点不构成圆!"<
return 0;
}
a=2*(x2-x1);
b=2*(y2-y1);
c=x2*x2+y2*y2-x1*x1-y1*y1;
d=2*(x3-x2);
e=2*(y3-y2);
f=x3*x3+y3*y3-x2*x2-y2*y2;
x=(b*f-e*c)/(b*d-e*a);
y=(d*c-a*f)/(b*d-e*a);
cout<<"圆心为("<
r=sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1));
cout<<"半径为"<
return 0;
}
#include
int main()
{
int x1,y1,x3,y3;
double a,b,c,d,e,f;
double r,k1,k2,x,y,x2,y2;
cout<<"请输入x1,y1,x2,y2,x3,y3"<
k1=1,k2=2;
if((y1==y2)&&(y2==y3))
{
cout<<"三点不构成圆!"<
}
if((y1!=y2)&&(y2!=y3))
{
k1=(x2-x1)/(y2-y1);
k2=(x3-x2)/(y3-y2);
}
if(k1==k2)
{
cout<<"三点不构成圆!"<
}
a=2*(x2-x1);
b=2*(y2-y1);
c=x2*x2+y2*y2-x1*x1-y1*y1;
d=2*(x3-x2);
e=2*(y3-y2);
f=x3*x3+y3*y3-x2*x2-y2*y2;
x=(b*f-e*c)/(b*d-e*a);
y=(d*c-a*f)/(b*d-e*a);
cout<<"圆心为("<
cout<<"半径为"<
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯