欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

UVA190 Circle Through Three Points

程序员文章站 2022-04-01 12:42:52
...
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;

double ax,ay,bx,by,cx,cy,x,y,a,b,c,p,r,f;
double A1,B1,A2,B2,C1,C2;

int main()
{
    while(cin>>ax>>ay>>bx>>by>>cx>>cy){
        a=pow((ax-bx)*(ax-bx)+(ay-by)*(ay-by),0.5);
		b=pow((ax-cx)*(ax-cx)+(ay-cy)*(ay-cy),0.5);
		c=pow((bx-cx)*(bx-cx)+(by-cy)*(by-cy),0.5);
		p=(a+b+c)*0.5;
		r=(a*b*c)/(4*pow(p*(p-a)*(p-b)*(p-c),0.5));

		A1=2*(bx-ax);
		B1=2*(by-ay);
		C1=bx*bx+by*by-ax*ax-ay*ay;
		A2=2*(cx-bx);
		B2=2*(cy-by);
		C2=cx*cx+cy*cy-bx*bx-by*by;
		x=((C1*B2)-(C2*B1))/((A1*B2)-(A2*B1));
		y=((A1*C2)-(A2*C1))/((A1*B2)-(A2*B1));

		f=r*r-x*x-y*y;

		cout << "(x " << (x>0?"- ":"+ ");
		printf("%.3f)^2 + (y ",abs(x));
		cout << (y>0?"- ":"+ ");
		printf("%.3f)^2 = %.3f^2\n",abs(y),r);

		cout << "x^2 + y^2 " << (x>0?"- ":"+ ");
		printf("%.3fx ",2*abs(x));
		cout << (y>0?"- ":"+ ");
		printf("%.3fy ",2*abs(y));
		cout << (f>0?"- ":"+ ");
		printf("%.3f = 0\n\n",abs(f));
    }
    return 0;
}