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

时间:2022-02-18 00:36:45

题目链接

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

 #include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;
#define eps 1e-8
struct point
{
double x,y;
};
struct line
{
point a,b;
};
point intersection(line u,line v)
{
point ret = u.a;
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))
/((u.a.x-u.b.x)*(v.a.y-v.b.y)-(u.a.y-u.b.y)*(v.a.x-v.b.x));
ret.x += (u.b.x-u.a.x)*t;
ret.y += (u.b.y-u.a.y)*t;
return ret;
}
point circumcenter(point a,point b,point c)
{
line u,v;
u.a.x = (a.x+b.x)/;
u.a.y = (a.y+b.y)/;
u.b.x = u.a.x - a.y + b.y;
u.b.y = u.a.y + a.x - b.x;
v.a.x = (a.x+c.x)/;
v.a.y = (a.y+c.y)/;
v.b.x = v.a.x - a.y + c.y;
v.b.y = v.a.y + a.x - c.x;
return intersection(u,v);
}
double dis(point p1,point p2)
{
return sqrt((p1.x-p2.x)*(p1.x-p2.x) + (p1.y-p2.y)*(p1.y-p2.y));
}
int main()
{
point p1,p2,p3,cr;
double r,c,d,e;
while(scanf("%lf%lf",&p1.x,&p1.y)!=EOF)
{
scanf("%lf%lf",&p2.x,&p2.y);
scanf("%lf%lf",&p3.x,&p3.y);
cr = circumcenter(p1,p2,p3);
r = dis(cr,p1);
cr.x = -cr.x;
cr.y = -cr.y;
if(cr.x > -eps)
printf("(x + %.3f)^2",cr.x+eps);
else
printf("(x - %.3f)^2",-(cr.x+eps));
if(cr.y > -eps)
printf(" + (y + %.3lf)^2 = ",cr.y+eps);
else
printf(" + (y - %.3lf)^2 = ",-(cr.y+eps));
printf("%.3lf^2\n",r+eps);
c = cr.x*;
d = cr.y*;
e = cr.x*cr.x + cr.y*cr.y - r*r;
printf("x^2 + y^2 ");
if(c > -eps)
printf("+ %.3fx ",c+eps);
else
printf("- %.3fx ",-(c+eps));
if(d > -eps)
printf("+ %.3fy ",d+eps);
else
printf("- %.3fy ",-(d+eps));
if(e > -eps)
printf("+ %.3f = 0\n\n",e+eps);
else
printf("- %.3f = 0\n\n",-(e+eps));
}
}