Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Solutions for "Three Points Circle" solution in Clear category for Three Points Circle by IvanowDenis
def checkio(data):
(x1,y1),(x2,y2),(x3,y3) = eval(data)
a, b, c = (x1**2 + y1**2), (x2**2 + y2**2), (x3**2 + y3**2)
xc = (a*(y2 - y3) - y1*(b - c) + (b * y3 - y2 * c))/ (x1 * (y2 - y3) - y1 * (x2 - x3) + (x2 * y3 - y2 * x3))/2
yc = (a*(x2 - x3) - x1*(b - c) + (b * x3 - x2 * c))/ (x1 * (y2 - y3) - y1 * (x2 - x3) + (x2 * y3 - y2 * x3))/(-2)
r = ((xc - x1)**2 + (yc - y1)**2)**.5
return "(x-%s)^2+(y-%s)^2=%s^2" % (str(round(xc, 2)).rstrip('.0'), str(round(yc, 2)).rstrip('.0'), str(round(r, 2)).rstrip('.0'))
#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"
Sept. 16, 2016