Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Three Points Circle solution in Clear category for Three Points Circle by IRONKAGE
from fractions import Fraction
from math import sqrt
def checkio(data):
(Ax, Ay), (Bx ,By), (Cx, Cy) = eval(data)
D = 2 * Ax * (By - Cy) + 2 * Bx * (Cy - Ay) + 2 * Cx * (Ay - By)
Ux = ( (Ax**2 + Ay**2) * (By - Cy) + (Bx**2 + By**2) * (Cy - Ay) + (Cx**2 + Cy**2) * (Ay - By) ) / D
Uy = ( (Ax**2 + Ay**2) * (Cx - Bx) + (Bx**2 + By**2) * (Ax - Cx) + (Cx**2 + Cy**2) * (Bx - Ax) ) / D
R = ( (Ax - Ux)**2 + (Ay - Uy)**2 ) ** 0.5
def f(num):
num = str(round(num, 2))
if num.endswith(".0"):
return num[:-2]
return num
return "(x-{0})^2+(y-{1})^2={2}^2".format(f(Ux), f(Uy), f(R))
return '(x-'+str(p[x])+')^2+(y-'+str(p[y])+')^2='+str(rad)+'^2'
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. 27, 2019