编写程序,输入平面上3个点,求过这3个点的圆的圆心和半径
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励30(财富值+成长值)
2015-06-05
展开全部
#include<iostream.h>
#include<math.h>
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"<<endl;
cin>>x1>>y1>>x2>>y2>>x3>>y3;
k1=1,k2=2;
if((y1==y2)&&(y2==y3))
{
cout<<"三点不构成圆!"<<endl;
return 0;
}
if((y1!=y2)&&(y2!=y3))
{
k1=(x2-x1)/(y2-y1);
k2=(x3-x2)/(y3-y2);
}
if(k1==k2)
{
cout<<"三点不构成圆!"<<endl;
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<<"圆心为("<<x<<","<<y<<")"<<endl;
r=sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1));
cout<<"半径为"<<r<<endl;
return 0;
}
#include<math.h>
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"<<endl;
cin>>x1>>y1>>x2>>y2>>x3>>y3;
k1=1,k2=2;
if((y1==y2)&&(y2==y3))
{
cout<<"三点不构成圆!"<<endl;
return 0;
}
if((y1!=y2)&&(y2!=y3))
{
k1=(x2-x1)/(y2-y1);
k2=(x3-x2)/(y3-y2);
}
if(k1==k2)
{
cout<<"三点不构成圆!"<<endl;
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<<"圆心为("<<x<<","<<y<<")"<<endl;
r=sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1));
cout<<"半径为"<<r<<endl;
return 0;
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询