Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Approximately Circle solution in Clear category for Three Points Circle by MrPod
def checkio(data):
(x1, y1), (x2, y2), (x3, y3) = eval(data)
if y1 == y2: y2, y3, x2, x3 = y3, y2, x3, x2
if y2 == y3: y2, y1, x2, x1 = y1, y2, x1, x2
mid = lambda a, b, c, d: ((a + b) / 2, (c + d) / 2)
gradient = lambda a, b, c, d: (a - b) / (c - d)
mid_a, mid_b = mid(x1, x2, y1, y2), mid(x2, x3, y2, y3)
gradient_a, gradient_b = gradient(x1, x2, y2, y1), gradient(x2, x3, y3, y2)
x = (mid_b[1] - mid_a[1] + gradient_a * mid_a[0] - gradient_b * mid_b[0]) / (gradient_a - gradient_b)
y = gradient_a * (x - mid_a[0]) + mid_a[1]
r = ((x1 - x)**2 + (y1 - y)**2)**.5
rounder = lambda z: int(z) if round(z, 2) == int(z) else round(z, 2)
return f'(x-{rounder(x)})^2+(y-{rounder(y)})^2={rounder(r)}^2'
Aug. 7, 2018
Comments: