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 TovarischZhukov
# migrated from python 2.7
def checkio(data):
c = eval(data)
x1 = c[0][0]
y1 = c[0][1]
x2 = c[1][0]
y2 = c[1][1]
x3 = c[2][0]
y3 = c[2][1]
a = x2-x1
b=y2-y1
c=x3-x1
d=y3-y1
e=a*(x1+x2)+b*(y1+y2)
f=c*(x1+x3)+d*(y1+y3)
g=2*(a*(y3-y2)-b*(x3-x2))
x=(d*e-b*f)/float(g)
y=(a*f-c*e)/float(g)
r = round(((x1-x)**2+(y1-y)**2)**0.5,2)
x= round(x,2)
y= round(y,2)
x = str(x) if str(x)[-1] != "0" else str(x)[:-2]
y = str(y) if str(y)[-1] != "0" else str(y)[:-2]
r = str(r) if str(r)[-1] != "0" else str(r)[:-2]
return "(x-%s)^2+(y-%s)^2=%s^2" % (str(x),str(y),str(r))
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
assert checkio("(2,2),(6,2),(2,6)") == "(x-4)^2+(y-4)^2=2.83^2"
assert checkio("(3,7),(6,9),(9,7)") == "(x-6)^2+(y-5.75)^2=3.25^2"
Dec. 13, 2015