1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
| #include <bits/stdc++.h> #define fi first #define se second using namespace std;
typedef pair<double, double> PII;
int T; struct Point{ double x, y; Point(){} Point(double xx, double yy) { x = xx; y = yy; } }; Point a, b, c; Point operator+(Point a, Point b) { return Point(a.x + b.x, a.y + b.y); } Point operator-(Point a, Point b) { return Point(a.x - b.x, a.y - b.y); } double sqr(double x) { return x * x; } double dis(Point a, Point b) { return sqrt(sqr(a.x - b.x) + sqr(a.y - b.y)); } Point gravity(Point a, Point b, Point c) { double x = (a.x + b.x + c.x) / 3; double y = (a.y + b.y + c.y) / 3; return Point(x, y); } Point Incenter(Point a, Point b, Point c) { double A = dis(b, c); double B = dis(a, c); double C = dis(a, b); double S = A + B + C; double x = (A * a.x + B * b.x + C * c.x) / S; double y = (A * a.y + B * b.y + C * c.y) / S; return Point(x, y); } Point Circum(Point a,Point b,Point c){ double x1=a.x,y1=a.y; double x2=b.x,y2=b.y; double x3=c.x,y3=c.y; double a1=2*(x2-x1); double b1=2*(y2-y1); double c1=x2*x2+y2*y2-x1*x1-y1*y1; double a2=2*(x3-x2); double b2=2*(y3-y2); double c2=x3*x3+y3*y3-x2*x2-y2*y2; double x=(c1*b2-c2*b1)/(a1*b2-a2*b1); double y=(a1*c2-a2*c1)/(a1*b2-a2*b1); return Point(x,y); }
Point Orthocenter(Point p0, Point p1 ,Point p2){ double a1,b1,a2,b2,c1,c2; a1 = p2.x-p1.x , b1=p2.y-p1.y , c1 = 0 ; a2 = p2.x-p0.x , b2=p2.y-p0.y , c2 = (p1.x-p0.x)*a2+(p1.y-p0.y)*b2 ; double d = a1 * b2 - a2 * b1; return Point(p0.x+(c1*b2-c2*b1)/d , p0.y+(a1*c2-a2*c1)/d) ; }
int main() { while(cin >> T, T) { scanf("%lf%lf", &a.x, &a.y); scanf("%lf%lf", &b.x, &b.y); scanf("%lf%lf", &c.x, &c.y); if(T == 1) { Point res = Circum(a, b, c); if(res.x == -0) res.x = 0; printf("Point O : (%.2lf, %.2lf)\n", res.x, res.y); } else if(T == 2) { Point res = Incenter(a, b, c); if(res.x == -0) res.x = 0; printf("Point I : (%.2lf, %.2lf)\n", res.x, res.y); } else if(T == 3) { Point res = gravity(a, b, c); if(res.x == -0) res.x = 0; printf("Point G : (%.2lf, %.2lf)\n", res.x, res.y); } else { Point res = Orthocenter(a, b, c); if(res.x == -0) res.x = 0; printf("Point H : (%.2lf, %.2lf)\n", res.x, res.y); } } return 0; }
|