Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Three Points Circle by tarjeii
from decimal import Decimal
def checkio(points):
""" Finds center of circle
Ref. webpage: http://www.regentsprep.org/regents/math/geometry/gcg6/RCir.htm
"""
points = points.translate(str.maketrans('(,)',' ')).split()
x1,y1,x2,y2,x3,y3 = map(int, points)
if x3 == x2 or x1 == x2:
x1,y1,x2,y2,x3,y3 = x2,y2,x3,y3,x1,y1
mr = (y2-y1)/(x2-x1)
mt = (y3-y2)/(x3-x2)
x = (mr*mt*(y3-y1)+mr*(x2+x3) - mt*(x1+x2))/(2*(mr-mt))
try:
y = -1/mt *(x-(x2+x3)/2) + (y2+y3)/2
except:
y = -1/mr *(x-(x1+x2)/2) + (y1+y2)/2
r = ((x1-x)**2+(y1-y)**2)**0.5
x,y,r = map(lambda f: int(f) if f.is_integer() else f, [round(x,2),round(y,2),round(r,2)])
return "(x-{})^2+(y-{})^2={}^2".format(x,y,r)
July 6, 2016