Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Three Points Circle solution in Uncategorized category for Three Points Circle by capback250
from math import sqrt
def reformat(points):
f1 = []
pairs = []
for x in points:
if x.isdigit():
f1.append(x)
for x in range(0, len(f1), 2):
a, b = f1[x], f1[x+1]
pairs.append([int(a), int(b)])
return pairs
def radius(points):
a, b, c = [x for x in reformat(points)]
la = sqrt((b[0]-a[0]) ** 2 + (b[1]-a[1]) ** 2)
lb = sqrt((c[0]-a[0]) ** 2 + (c[1]-a[1]) ** 2)
lc = sqrt((b[0]-c[0]) ** 2 + (b[1]-c[1]) ** 2)
return round(la*lb*lc/sqrt((la+lb+lc)*(-la+lb+lc)*(la-lb+lc)*(la+lb-lc)), 2)
def checkio(points):
a, b, c = [x for x in reformat(points)]
x1, y1 = a[0], a[1]
x2, y2 = b[0], b[1]
x3, y3 = c[0], c[1]
m = (x1-x2)*(y1-y3) - (x1-x3)*(y1-y2)
m1 = (x1**2-x2**2+y1**2-y2**2)/2.0*(y1 - y3) - (x1**2-x3**2+y1**2-y3**2)/2.0*(y1 - y2)
m2 = (x1-x2)*((x1**2-x3**2+y1**2-y3**2)/2.0) - (x1-x3)*(x1**2-x2**2+y1**2-y2**2)/2.0
return "(x-{:g})^2+(y-{:g})^2={:g}^2".format(round(m1/m, 2), round(m2/m, 2), radius(points))
Sept. 7, 2015