UVA12302 Nine-Point Circle
九点圆过 三边中点、三边垂足、三点至垂心线段的中点。
九点圆圆心为外心与垂心中点,半径为外心的一半。
也许是精度问题,求三边中点三角形外心再求距离算半径就WA了。
1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 #include<math.h> 5 struct Point 6 { 7 double x, y; 8 Point(){x = y = 0;} 9 Point(double a, double b) 10 {x = a, y = b;} 11 Point operator-(const Point &b)const 12 {return Point(x - b.x, y - b.y);} 13 Point operator+(const Point &b)const 14 {return Point(x + b.x, y + b.y);} 15 Point operator-() 16 {return Point(-x, -y);} 17 Point operator*(const double &b)const 18 {return Point(x * b, y * b);} 19 double dot(const Point &b)const 20 {return x * b.x + y * b.y;} 21 double cross(const Point &b, const Point &c)const 22 {return (b.x - x) * (c.y - y) - (c.x - x) * (b.y - y);} 23 double Dis(const Point &b)const 24 {return sqrt((*this - b).dot(*this - b));} 25 }; 26 Point CrossPoint(Point a, Point b, Point c, Point d) 27 { 28 double u = a.cross(b, c), v = b.cross(a, d); 29 return Point((c.x * v + d.x * u) / (u + v), (c.y * v + d.y * u) / (u + v)); 30 } 31 Point A, B, C, ab, ac, Rcx, Rwx, r; 32 int main() 33 { 34 while(scanf("%lf%lf%lf%lf%lf%lf", &A.x, &A.y, &B.x, &B.y, &C.x, &C.y), 35 fabs(A.x + 1) > 1e-8) 36 { 37 Rcx = CrossPoint(A, Point(A.x + B.y - C.y, A.y + C.x - B.x), 38 B, Point(B.x + C.y - A.y, B.y + A.x - C.x)); 39 ab = (A + B) * 0.5, ac = (A + C) * 0.5; 40 Rwx = CrossPoint(ab, Point(ab.x + B.y - A.y, ab.y + A.x - B.x), 41 ac, Point(ac.x + C.y - A.y, ac.y + A.x - C.x)); 42 r = (Rcx + Rwx) * 0.5; 43 printf("%.6f %.6f %.6f\n", r.x, r.y, Rwx.Dis(A) * 0.5); 44 } 45 return 0; 46 }