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 aya.kanazawa
from sympy import *
import math
import re
def checkio(data):
(xa, ya), (xb, yb), (xc, yc) = eval(data)
# length of AO (O=central point)
xo, yo = symbols('xo yo', real=True)
init_printing()
solved = solve([abs(xa - xo) ** 2 + abs(ya - yo) ** 2 - (abs(xb - xo) ** 2 + abs(yb - yo) ** 2),
abs(xa - xo) ** 2 + abs(ya - yo) ** 2 - (abs(xc - xo) ** 2 + abs(yc - yo) ** 2)], [xo, yo])
xo, yo = float(solved[xo]), float(solved[yo])
print(f'xo, yo={(xo, yo)}')
r = round(math.sqrt(abs(xa - xo) ** 2 + abs(ya - yo) ** 2), 2)
print(f'r={r}')
result = re.sub('\.0([^\d])', '\\1', f'(x-{round(xo,2)})^2+(y-{round(yo,2)})^2={r}^2')
print(result)
return result
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
assert checkio("(6,6),(2,9),(1,6)") == "(x-3.5)^2+(y-6.83)^2=2.64^2"
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"
May 22, 2019