/*
Subject: #190 - Circle Through Three Points
e-mail: morcavon@gmail.com
Homepage: http://www.morcavon.com
Building: 10/08/2005 ~ 11/08/2005
Last Update: 11/08/2005
*/
/*
<PURPOSE>
Determine an outer center of triangle.
-
<PREDICATE>
The three points will not be on a straight line.
-
<INPUT>
Three points of triangle.
-
<OUTPUT>
(x - h)^2 + (y - k)^2 = r^2 : each values must print with tree digit atfer the decimal
x^2 + y^2 + cx + dy + e = 0
*/
#include <stdio.h>
#include <math.h>
int main()
{
double p[2], q[2], r[2];
double h, k, sqr_rad, cx, dy, e;
double a, b, c, d, a2, b2, c2, d2;
while (scanf("%lf %lf %lf %lf %lf %lf", &p[0], &p[1], &q[0], &q[1], &r[0], &r[1]) != EOF) {
a = p[0] + q[0];
b = p[0] - q[0];
c = p[1] + q[1];
d = p[1] - q[1];
a2 = q[0] + r[0];
b2 = q[0] - r[0];
c2 = q[1] + r[1];
d2 = q[1] - r[1];
if (b2 == 0.0f) {
/* b2와 d2 둘다 0이 될 수 없다(그렇게 되면 q, r이 같은 점이 되기 땜에..) */
k = c2 / 2.0f;
/* b는 0이 아님(b가 0일경우 세 점이 일직선에 놓이게 된다.) */
h = (a*b + c*d - 2.0f*d*k) / (2*b);
}
else if (b == 0.0f) { /* b2 != 0 */
k = c / 2.0f;
h = (a2*b2 + c2*d2 - 2.0f*d2*k) / (2*b2);
}
else { /* b, b2 둘다 0이 아닌 일반적인 경우=_= */
k = ((((a*b + c*d)*b2) - ((a2*b2 + c2*d2)*b)) / (2.0f*b2)) / (d - (d2*b/b2));
h = (a*b + c*d - 2.0f*d*k) / (2*b);
}
sqr_rad = (p[0] - h)*(p[0] - h) + (p[1] - k)*(p[1] - k);
cx = -2.0f * h;
dy = -2.0f * k;
e = h*h + k*k - sqr_rad;
/* (x - h)^2 + (y - k)^2 = r^2 */
printf("(x %c %.3lf)^2 + (y %c %.3lf)^2 = %.3lf^2\n",
(h < 0.0f) ? '+':'-', fabs(h),
(k < 0.0f) ? '+':'-', fabs(k),
sqrt(sqr_rad));
/* x^2 + y^2 + cx + dy + e = 0 */
printf("x^2 + y^2 %c %.3lfx %c %.3lfy %c %.3lf = 0\n\n",
(cx < 0.0f) ? '-':'+', fabs(cx),
(dy < 0.0f) ? '-':'+', fabs(dy),
(e < 0.0f) ? '-':'+', fabs(e));
}
return 0;
}