POJ 1329 Circle Through Three Points(三角形外心)

题目链接

抄的外心模版。然后,输出认真一点。1Y。

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <string>
 4 #include <cmath>
 5 #include <algorithm>
 6 using namespace std;
 7 #define eps 1e-8
 8 struct point
 9 {
10     double x,y;
11 };
12 struct line
13 {
14     point a,b;
15 };
16 point intersection(line u,line v)
17 {
18     point ret = u.a;
19     double t = ((u.a.x-v.a.x)*(v.a.y-v.b.y)-(u.a.y-v.a.y)*(v.a.x-v.b.x))
20     /((u.a.x-u.b.x)*(v.a.y-v.b.y)-(u.a.y-u.b.y)*(v.a.x-v.b.x));
21     ret.x += (u.b.x-u.a.x)*t;
22     ret.y += (u.b.y-u.a.y)*t;
23     return ret;
24 }
25 point circumcenter(point a,point b,point c)
26 {
27     line u,v;
28     u.a.x = (a.x+b.x)/2;
29     u.a.y = (a.y+b.y)/2;
30     u.b.x = u.a.x - a.y + b.y;
31     u.b.y = u.a.y + a.x - b.x;
32     v.a.x = (a.x+c.x)/2;
33     v.a.y = (a.y+c.y)/2;
34     v.b.x = v.a.x - a.y + c.y;
35     v.b.y = v.a.y + a.x - c.x;
36     return intersection(u,v);
37 }
38 double dis(point p1,point p2)
39 {
40     return sqrt((p1.x-p2.x)*(p1.x-p2.x) + (p1.y-p2.y)*(p1.y-p2.y));
41 }
42 int main()
43 {
44     point p1,p2,p3,cr;
45     double r,c,d,e;
46     while(scanf("%lf%lf",&p1.x,&p1.y)!=EOF)
47     {
48         scanf("%lf%lf",&p2.x,&p2.y);
49         scanf("%lf%lf",&p3.x,&p3.y);
50         cr = circumcenter(p1,p2,p3);
51         r = dis(cr,p1);
52         cr.x = -cr.x;
53         cr.y = -cr.y;
54         if(cr.x > -eps)
55         printf("(x + %.3f)^2",cr.x+eps);
56         else
57         printf("(x - %.3f)^2",-(cr.x+eps));
58         if(cr.y > -eps)
59         printf(" + (y + %.3lf)^2 = ",cr.y+eps);
60         else
61         printf(" + (y - %.3lf)^2 = ",-(cr.y+eps));
62         printf("%.3lf^2
",r+eps);
63         c = cr.x*2;
64         d = cr.y*2;
65         e = cr.x*cr.x + cr.y*cr.y - r*r;
66         printf("x^2 + y^2 ");
67         if(c > -eps)
68         printf("+ %.3fx ",c+eps);
69         else
70         printf("- %.3fx ",-(c+eps));
71         if(d > -eps)
72         printf("+ %.3fy ",d+eps);
73         else
74         printf("- %.3fy ",-(d+eps));
75         if(e > -eps)
76         printf("+ %.3f = 0

",e+eps);
77         else
78         printf("- %.3f = 0

",-(e+eps));
79     }
80 }
原文地址:https://www.cnblogs.com/naix-x/p/3369193.html