杭电acm1374

http://acm.hdu.edu.cn/showproblem.php?pid=1374

给出三个点的坐标,设为A(x1,y1),B (x2, y2),C (x3, y3),然后求出通过这三点的圆的周长(保留两位小数)。但推导公式却比较麻烦,我是这样来做的。
      首先根据同一个弦的圆心角角度相同,不难得出,圆周的直径d= BC/ sin a = AC/ sin b = AB/sin c;
      因此求圆周长= BC / sin (a) *PI;
      其中BC为角a的对边长度= sqrt ( (x2-x3)^2 + (y2-y3)^2);
      至于sin (a),我们必须通过三点坐标来算,比较麻烦一些,可以利用三角函数的公式:
   先用余弦定理解出cosa,然后由sqrt(1-cosa*cosa)求sina;
  其中cosa=(b*b+c*c-a*a)/(2*b*c);
 
      
View Code
 1 #include<stdio.h>
 2 #include<math.h>
 3 #define PI 3.141592653589793
 4 int main()
 5 {
 6   double x1,y1,x2,y2,x3,y3,a,b,c;
 7    double sinA,R,cosA;
 8    while((scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3))!=EOF)
 9        {
10           a=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
11           b=sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3));
12           c=sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2));
13           cosA=(b*b+c*c-a*a)/(2*b*c);
14           sinA=sqrt(1-cosA*cosA);
15           R=a/sinA;
16           printf("%.2lf\n",R*PI);
17        }
18  return 0;
19 }
原文地址:https://www.cnblogs.com/huzhenbo113/p/3066772.html