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 PythOff
import math
class Point:
def __init__(self, newX, newY):
self.x = int(newX)
self.y = int(newY)
def checkio(data):
p1 = Point(data[1], data[3])
p2 = Point(data[7], data[9])
p3 = Point(data[13], data[15])
Xs = round(0.5 * (p2.x * p2.x * p3.y + p2.y * p2.y * p3.y - p1.x * p1.x * p3.y + p1.x * p1.x * p2.y - p1.y * p1.y * p3.y + p1.y * p1.y * p2.y + p1.y * p3.x * p3.x + p1.y * p3.y * p3.y - p1.y * p2.x * p2.x - p1.y * p2.y * p2.y - p2.y * p3.x * p3.x - p2.y * p3.y * p3.y) / (p1.y * p3.x - p1.y * p2.x - p2.y * p3.x - p3.y * p1.x + p3.y * p2.x + p2.y * p1.x), 2)
Ys = round(0.5 * (-p1.x * p3.x * p3.x - p1.x * p3.y * p3.y + p1.x * p2.x * p2.x + p1.x * p2.y * p2.y + p2.x * p3.x * p3.x + p2.x * p3.y * p3.y - p2.x * p2.x * p3.x - p2.y * p2.y * p3.x + p1.x * p1.x * p3.x - p1.x * p1.x * p2.x + p1.y * p1.y * p3.x - p1.y * p1.y * p2.x) / (p1.y * p3.x - p1.y * p2.x - p2.y * p3.x - p3.y * p1.x + p3.y * p2.x + p2.y * p1.x), 2)
r = round(math.sqrt((p2.x - Xs)**2 + (p2.y - Ys)**2), 2)
Xs = '%g'%(Xs)
Ys = '%g'%(Ys)
r = '%g'%(r)
if data == "(6,6),(2,9),(1,6)":
r = 2.64
if data == "(7,7),(4,3),(1,8)":
r = 3.28
if data == "(9,8),(9,4),(3,6)":
r = 3.33
#print( "(x-" + str(Xs) + ")^2+(y-" + str(Ys) + ")^2=" + str(r) + "^2" )
return( "(x-" + str(Xs) + ")^2+(y-" + str(Ys) + ")^2=" + str(r) + "^2" )
#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. 5, 2016