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 iwo.malyszka
import math
def is_point_zero(m):
if (int(m) / round(m, 2)) == 1:
return int(m)
else:
return round(m, 2)
def checkio(data):
tab = []
for item in data:
if item.isdigit():
tab.append(int(item))
x1, y1, x2, y2, x3, y3 = tab[0], tab[1], tab[2], tab[3], tab[4], tab[5]
d = 2.0 * ((y1 - y3) * (x1 - x2) - (y1 - y2) * (x1 - x3))
x = ((y1 - y3) * (y1 ** 2 - y2 ** 2 + x1 ** 2 - x2 ** 2) - (y1 - y2)
* (y1 ** 2 - y3 ** 2 + x1 ** 2 - x3 ** 2)) / d
y = ((x1 - x3) * (x1 ** 2 - x2 ** 2 + y1 ** 2 - y2 ** 2) - (x1 - x2)
* (x1 ** 2 - x3 ** 2 + y1 ** 2 - y3 ** 2)) / -d
r = math.sqrt((x - x1) ** 2 + (y - y1) ** 2)
return "(x-{0})^2+(y-{1})^2={2}^2".format(is_point_zero(x), is_point_zero(y), is_point_zero(r))
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"
Oct. 27, 2016