Example #1
0
 Circle(const Point& P1, const Point& P2, const Point& P3) {
   double d1 = P1.CalcDist(P2);
   double d2 = P1.CalcDist(P3);
   double d3 = P2.CalcDist(P3);
   if (fabs(d1+d2-d3) <= EPS) {
     Circle circle(P2, P3);
     center = circle.center;
     radius = circle.radius;
   } else if (fabs(d1+d3-d2) <= EPS) {
     Circle circle(P1, P3);
     center = circle.center;
     radius = circle.radius;
   } else if (fabs(d2+d3-d1) <= EPS) {
     Circle circle(P1, P2);
     center = circle.center;
     radius = circle.radius;
   } else {
     Point M1 = Point((P1.x + P2.x) / 2, (P1.y + P2.y) / 2);
     Point V = P2-P1;
     Point D1 = Point(-V.y, V.x);
     Point W = P3-P1;
     Point M2 = Point((P1.x + P3.x) / 2, (P1.y + P3.y) / 2);
     Point D2 = Point(-W.y, W.x);
     assert(fabs(D1.x*D2.y - D1.y*D2.x) > EPS);
     double alpha = (D2.y*(M2.x-M1.x) - D2.x*(M2.y-M1.y)) / (D1.x*D2.y - D1.y*D2.x);
     center = Point(M1.x + alpha*D1.x, M1.y + alpha*D1.y);
     radius = center.CalcDist(P1);
     assert(fabs(radius - center.CalcDist(P2)) < EPS);
     assert(fabs(radius - center.CalcDist(P3)) < EPS);
   }
 }
Example #2
0
 int Contains(const Point& P) const {
   return center.CalcDist(P) <= radius + EPS;
 }
Example #3
0
 Circle(const Point& P1, const Point& P2) {
   center = Point((P1.x + P2.x) / 2, (P1.y + P2.y) / 2);
   radius = center.CalcDist(P2);
 }