Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
So math. Much easy. Wow solution in Speedy category for Three Points Circle by Renelvon
import math
import re
def checkio(data):
x0, y0, x1, y1, x2, y2 = (int(s) for s in re.compile('\d+').findall(data))
"""
Equation of line bisector of points (x0, y0), (x1, y1):
2(x1 - x0)x + 2(y1 - y0)y = (x1^2 - x0^2) + (y1^2 - y0^2)
See: http://mathhelpforum.com/pre-calculus/64489-analytic-geometry.html
"""
# Form the equations of the 2 line bisectors
A0, B0, C0 = 2*(x1 - x0), 2*(y1 - y0), x1**2 - x0**2 + y1**2 - y0**2
A1, B1, C1 = 2*(x2 - x1), 2*(y2 - y1), x2**2 - x1**2 + y2**2 - y1**2
#Solve system using Crammer's rule
det = A0*B1 - A1*B0
xc, yc = (C0*B1 - C1*B0) / det, (A0*C1 - A1*C0) / det
radius = math.hypot((xc - x0), (yc - y0))
xxc, yyc, rradius = round(xc, 2), round(yc, 2), round(radius, 2)
return "(x-%.3g)^2+(y-%.3g)^2=%.3g^2" % (xxc, yyc, rradius)
June 10, 2014