joj 1805
求外接圆圆心的一道题
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
struct Point{
double x;
double y;
};
Point circle_center(Point pt[3])
{
double x1,x2,x3,y1,y2,y3;
double x = 0;
double y = 0;
x1 = pt[0].x;
x2 = pt[1].x;
x3 = pt[2].x;
y1 = pt[0].y;
y2 = pt[1].y;
y3 = pt[2].y;
x=((y2-y1)*(y3*y3-y1*y1+x3*x3-x1*x1)-(y3-y1)*(y2*y2-y1*y1+x2*x2-x1*x1))/(2*(x3-x1)*(y2-y1)-2*((x2-x1)*(y3-y1)));
y=((x2-x1)*(x3*x3-x1*x1+y3*y3-y1*y1)-(x3-x1)*(x2*x2-x1*x1+y2*y2-y1*y1))/(2*(y3-y1)*(x2-x1)-2*((y2-y1)*(x3-x1)));
Point center;
center.x = x ;
center.y = y ;
return center;
}
int main()
{
Point p[3];
while(scanf("%lf%lf%lf%lf%lf%lf",&p[0].x,&p[0].y,&p[1].x,&p[1].y,&p[2].x,&p[2].y)!=EOF)
{
Point c=circle_center(p);
double r=sqrt((p[0].x-c.x)*(p[0].x-c.x)+(p[0].y-c.y)*(p[0].y-c.y));
printf("(x");
if(c.x>0)
printf(" - %.3lf",fabs(c.x));
if(c.x<0)
printf(" + %.3lf",fabs(c.x));
printf(")^2 + (y");
if(c.y>0)
printf(" - %.3lf",fabs(c.y));
if(c.y<0)
printf(" + %.3lf",fabs(c.y));
printf(")^2 = %.3lf^2\n",fabs(r));
double p=c.x*c.x+c.y*c.y-r*r;
double c1=2*c.x;
double c2=2*c.y;
printf("x^2 + y^2");
if(c1>0)
printf(" - %.3lfx",fabs(c1));
if(c1<0)
printf(" + %.3lfx",fabs(c1));
if(c2>0)
printf(" - %.3lfy",fabs(c2));
if(c2<0)
printf(" + %.3lfy",fabs(c2));
if(p>0)
printf(" + %.3lf",fabs(p));
if(p<0)
printf(" - %.3lf",fabs(p));
printf(" = 0\n");
printf("\n");
}
}