1. 
package acm_190_circle_through_three_points;

import java.util.Scanner;

/**
* FWP, Ausgew¦hlte Probleme aus dem ACM Programming Contest, SS10
* Problem: acm_190_circle_through_three_points
* Link:
*
* @author Martin Lambeck
* @version 1.0, 07.09.2010
*
* Method : geometry
* Status : Accepted
* Runtime: 0.168
*/


public class Main
{
static Point p1;
static Point p2;
static Point p3;

static Scanner sc = new Scanner(System.in);

public static void main (String...args)
{
while (testcase());
}

public static boolean testcase()
{
double x, y;
double frac, denom;
double r;


if (!sc.hasNextDouble())
return false;

p1 = new Point(sc.nextDouble(), sc.nextDouble());
p2 = new Point(sc.nextDouble(), sc.nextDouble());
p3 = new Point(sc.nextDouble(), sc.nextDouble());

Point m1 = mid(p1, p2); //middle point of p1->p2
Point m2 = mid(p2, p3); //middle point of p2->p3

Vector v1 = ortho(m1, p2); //v1 orthogonal to m1->p2
Vector v2 = ortho(m2, p3); //v2 orthogonal to m2->p3


// m1 + t * v1 = m2 + s * v2
//
// I) m1.x + t * v1.x = m2.x + s * v2.x
// II) m1.y + t * v1.y = m2.y + s * v2.y
//
// t = ... * s
// eliminate t => s = ... = frac
//
// x,y = center of circle = m2 + v2 * s = m2 + v2 * frac

denom = (v1.y * v2.x - v1.x * v2.y);
frac = (v1.x * (m2.y - m1.y) - v1.y * (m2.x - m1.x)) / denom;

if (denom == 0)
throw new IllegalArgumentException(); //wont happen, there is no such testcase

x = m2.x + v2.x * frac;
y = m2.y + v2.y * frac;


r = Math.hypot(p1.x - x, p1.y - y);

String sx = (x < 0 ? "+" : "-");
String sy = (y < 0 ? "+" : "-");

System.out.printf("(x %s %.3f)^2 + (y %s %.3f)^2 = %.3f^2%n", sx, Math.abs(x), sy, Math.abs(y), r);


double sq = x*x + y*y - r*r;

String ssq = (sq < 0 ? "-" : "+");

System.out.printf("x^2 + y^2 %s %.3fx %s %.3fy %s %.3f = 0%n%n", sx, Math.abs(2*x), sy, Math.abs(2*y), ssq, Math.abs(sq));


return true;
}

public static Point mid(Point p1, Point p2)
{
double x = (p2.x - p1.x) / 2.0 + p1.x;
double y = (p2.y - p1.y) / 2.0 + p1.y;

return new Point (x, y);
}
public static Vector ortho(Point p0, Point q)
{
double x = q.x - p0.x;
double y = q.y - p0.y;

return new Vector(y, -x);
}

}

class Point
{
double x;
double y;

public Point(double xx, double yy)
{
x = xx;
y = yy;
}
}

class Vector
{
double x;
double y;

public Vector(double xx, double yy)
{
x = xx;
y = yy;
}
}