FZU 1382(三角形の外接円と内接円を求めます)

6290 ワード

 1 /*

 2 *      :                 

 3 *       :r=2*s/(a+b+c) ;

 4 *         R=(a*b*c)/(s*4);

 5 *          ,         :   

 6 *  r=sqrt[(p-a)(p-b)(p-c)/p]   

 7 *             ,         :

 8 *  1、               2,         。

 9 *  2、               ,         。   

10 *  1、r=(a+b-c)/2( :s Rt△   ,a, b Rt△ 2    ,c   )   

11 *  2、r=ab/ (a+b+c) 

12 */

13 

14 #include <cmath>

15 #include <cstdio>

16 #include <cstdlib>

17 #include <iostream>

18 

19 using namespace std;

20 

21 const double PI = 3.14159265;

22 

23 struct point {

24     double x;

25     double y;

26     double z;

27 }A, B, C;

28 

29 double dis(point A, point B) {

30     return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y)+(A.z-B.z)*(A.z-B.z));

31 }

32 

33 double solve() {

34     double a = dis(A, B);

35     double b = dis(A, C);

36     double c = dis(B, C);

37     double p = (a + b + c) / 2;

38     double r1 = sqrt((p-a)*(p-b)*(p-c)/p);  //      

39     double area1 = PI * r1 * r1;

40     double area = sqrt((p-a)*(p-b)*(p-c)*p);

41     double r2 =  a * b * c / (area * 4);  //      

42     double area2 =  PI * r2 * r2;

43     return  area1 / area2;

44 }

45 

46 int  main() {

47     while (scanf("%lf%lf%lf%lf%lf%lf%lf%lf%lf", &A.x, &A.y, &A.z, &B.x, &B.y, &B.z, &C.x, &C.y, &C.z) != EOF) {

48         double ans = solve();

49         printf ("%.3lf
", ans); 50 } 51 return 0; 52 }