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 Piotr.Helminiak
import math
def checkio(data):
x1=int(data[1])
y1=int(data[3])
x2=int(data[7])
y2=int(data[9])
x3=int(data[13])
y3=int(data[15])
d = 2 * ((y1 - y3) * (x1 - x2) - (y1 - y2) * (x1 - x3))
x0 = (((y1 - y3) * (y1 ** 2 - y2 ** 2 + x1 ** 2 - x2 ** 2) - (y1 - y2) * (y1 ** 2 - y3 ** 2 + x1 ** 2 - x3 ** 2)) / d)
y0 = (((x1 - x3) * (x1 ** 2 - x2 ** 2 + y1 ** 2 - y2 ** 2) - (x1 - x2) * (x1 ** 2 - x3 ** 2 + y1 ** 2 - y3 ** 2)) / -d)
r=round(math.sqrt((x1-x0)**2+(y1-y0)**2),2)
return "(x-{:g})^2+(y-{:g})^2={:g}^2".format(round(x0,2),round(y0,2),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"
Nov. 10, 2016