Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Three Points Circle by Moff
import re
import math
def det3(m):
return m[0][0] * (m[1][1] * m[2][2] - m[1][2] * m[2][1]) + m[0][1] * (m[1][2] * m[2][0] - m[1][0] * m[2][2]) + \
m[0][2] * (m[1][0] * m[2][1] - m[1][1] * m[2][0])
def format_float(f, pattern='{:+.2f}'):
s = pattern.format(f)
while s[-1] in '.0':
s = s[:-1]
return s
def checkio(n):
xa, ya, xb, yb, xc, yc = map(int, re.findall('(\d+)', n))
d = 2 * det3([[xa, ya, 1], [xb, yb, 1], [xc, yc, 1]])
xo = det3([[xa**2 + ya**2, ya, 1], [xb**2 + yb**2, yb, 1], [xc**2 + yc**2, yc, 1]]) / d
yo = -det3([[xa**2 + ya**2, xa, 1], [xb**2 + yb**2, xb, 1], [xc**2 + yc**2, xc, 1]]) / d
return '(x{})^2+(y{})^2={}^2'.format(
format_float(-xo), format_float(-yo), format_float(math.hypot(xa-xo, ya-yo), '{:.2f}'))
Aug. 1, 2015