{ Calculate center and radius of circle based on three points in the plane. Beware colinear points and points parallel to y-axis. 6/4/2002 Greg Ward solution due to Paul Bourke Inputs: x1,y1,x2,y2,x3,y3 - points on circle Outputs: xc, yc, r - center and radius } sq(x) : x*x; ma = (y2-y1)/(x2-x1); mb = (y3-y2)/(x3-x2); xc = (ma*mb*(y1-y3) + mb*(x1+x2) - ma*(x2+x3)) / (2*(mb-ma)); yc = ((x1+x2)/2 - xc)/ma + (y1+y2)/2; r = sqrt(sq(x2-xc) + sq(y2-yc));