題意:給你三個圓上的點,求圓的兩種表達式。首先普及知識:
外接圓半徑:公式:a/sinA=b/sinB=c/sinC=2R (R就是外接圓半徑)
本題可以這樣:①.先利用余弦定理:a^2=b^2+c^2-2bc·cosA
求出:cosA=(b^2+c^2-a^2)/2bc 在利用公式:sinA^2+cosA^2=1
確定 sinA=根號(1-cosA^2) =根號[(a^2+b^2+c^2)^2-2(a^4+b^4+c^4)]/(2bc)
然後代入 a/sinA=2R求出R. R=abc/根號[(a^2+b^2+c^2)^2-2(a^4+b^4+c^4)]
定義:設平面上的三點A(x1,y1),B(x2,y2),C(x3,y3),定義
S(A,B,C) = (x1-x3)*(y2-y3) - (y1-y3)*(x2-x3)
已知三角形的三個頂點為A(x1,y1),B(x2,y2),C(x3,y3),則該三角形的外心為:
S((x1*x1+y1*y1, y1), (x2*x2+y2*y2, y2), (x3*x3+y3*y3, y3))
x0 = -----------------------------------------------------------
2*S(A,B,C)
S((x1,x1*x1+y1*y1), (x2, x2*x2+y2*y2), (x3, x3*x3+y3*y3))
y0 = -----------------------------------------------------------
2*S(A,B,C)
把圓心的坐標和半徑求出來之後就輸出。
代碼:
[cpp]
#include<iostream>
#include<cmath>
using namespace std;
double Dist(double x,double y,double x1,double y1)
{
return (x-x1)*(x-x1)+(y-y1)*(y-y1);
}
double Sn(double x1,double y1,double x2,double y2,double x3,double y3)
{
return (x1-x3)*(y2-y3)-(y1-y3)*(x2-x3);
}
void Fn(double x)
{
if(x<0) printf(" + %.3lf",-x);
else printf(" - %.3lf",x);
}
int main()
{
double x1,x2,x3,y1,y2,y3,x,y;
while( scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3)!=EOF){
double a=Dist(x1,y1,x2,y2);
double b=Dist(x2,y2,x3,y3);
double c=Dist(x3,y3,x1,y1);
double r=sqrt(a*b*c)/sqrt((a+b+c)*(a+b+c)-2*(a*a+b*b+c*c));
// printf("%.lf\n",r);
double s=Sn(x1,y1,x2,y2,x3,y3);
double s1=Sn( x1*x1+y1*y1, y1, x2*x2+y2*y2, y2, x3*x3+y3*y3, y3);
double s2=Sn( x1,x1*x1+y1*y1, x2, x2*x2+y2*y2, x3, x3*x3+y3*y3);
x=s1/(2*s); www.2cto.com
y=s2/(2*s);
printf("(x");
Fn(x);
printf(")^2 + (y");
Fn(y);
printf(")^2 = %.3lf^2\n",r);
printf("x^2 + y^2");
Fn(2*x); printf("x");
Fn(2*y); printf("y");
Fn(r*r-x*x-y*y);
printf(" = 0\n\n");
}
return 0;
}