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 cinekk
from math import sqrt
def io(number):
if int(number) == number:
return str(int(number))
if str(round(number,2))[-1] == '0':
return str(round(number,2))[:-2]
return round(number,2)
def checkio(data):
x, y, r = 0, 0, 0.0
(a1,a2), (b1,b2), (c1,c2) = eval(data)
f = 2 * ((a2 - c2) * (a1 - b1) - (a2 -b2) * (a1 - c1))
x = ((a2 - c2) * (a2 ** 2 - b2 ** 2 + a1 ** 2 - b1 ** 2) - (a2 - b2)
* (a2 ** 2 - c2 ** 2 + a1 ** 2 - c1 ** 2)) / f
y = ((a1 - c1) * (a1 ** 2 - b1 ** 2 + a2 ** 2 - b2 ** 2) - (a1 - b1)
* (a1 ** 2 - c1 ** 2 + a2 ** 2 - c2 ** 2)) / (-f)
r = sqrt((x - a1) ** 2 + (y - a2) ** 2)
return "(x-{0})^2+(y-{1})^2={2}^2".format(io(x),io(y),io(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. 29, 2016