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 Lachesis_132296
import cmath
def equation(x, y, r):
w = "(x-" + x + ")^2+(y-" + y + ")^2=" + r + "^2"
return w
def complex_r(x):
x = str(x)
i = x.find('.')
x = x[1:i+4]
# print(x)
if x[len(x)-1].isdigit():
if int(x[len(x)-1])>=5:
#print("wieksze równe 5: ", x, "\nx[i] = ", x[len(x)-1])
x = x[:len(x)-1]
#print("sciete o 1: ", x)
digit = x[len(x)-1]
digit = int(digit)+1
x = x[:len(x)-1]
x = x + str(digit)
#print("poprawne: ", x)
else:
x = x[:len(x)-1]
else:
x = x[:len(x) - 1]
i = x.find('.')
n = len(x)
if i+1 < n and n == i+2 and x[i+1] == '0' and x[i] == '.': #coś.0
x = x[:n-2]
elif i+2 < n and x[i+2] == '0' and x[i+1] != '0': #coś.d0, gdzie d - cyfra różna od 0
x = x[:n-1]
elif i+2 < n and x[i+2] == '0' and x[i+1] == '0' and x[i] == '.':
x = x[:n-3]
if x[len(x)-1].isdigit():
return x
else:
x = x[:len(x)-1]
return x
def rounding (x):
x = round(x, 2)
x = str(x)
i = x.find('.')
n = len(x)
#print("x round = ", x)
if i+1 < n and n == i+2 and x[i+1] == '0' and x[i] == '.': #coś.0
x = x[:n-2]
elif i+2 < n and x[i+2] == '0': #coś.d0, gdzie d - cyfra różna od 0
x = x[:n-1]
elif i+2 < n and x[i+2] == '0' and x[i+1] == '0' and x[i] == '.':
x = x[:n-3]
return x
def checkio(data):
x1 = int(data[1])
y1 = int(data[3])
x2 = int(data[7])
y2 = int(data[9])
x3 = int(data[13])
y3 = int(data[15])
#print("x1 = ", x1, "\ny1 = ", y1, "\nx2 = ", x2, "\ny2 = ", y2, "\nx3 = ", x3, "\ny3 = ", y3)
xs = 0.5*(x2*x2*y3+y2*y2*y3-x1*x1*y3-y1*y1*y3+x1*x1*y2+y1*y1*y2-x3*x3*y2-y3*y3*y2+x3*x3*y1+y3*y3*y1-x2*x2*y1-y2*y2*y1)/(y1*x3-y1*x2+y2*x1-y2*x3+y3*x2-y3*x1)
ys = 0.5*(-x1*x3*x3-x1*y3*y3+x1*x2*x2+x1*y2*y2+x2*x3*x3+x2*y3*y3-x2*x2*x3-y2*y2*x3+x1*x1*x3-x1*x1*x2+y1*y1*x3-y1*y1*x2)/(y1*x3-y1*x2-y2*x3-y3*x1+y3*x2+y2*x1)
r = cmath.sqrt((x1-xs)*(x1-xs)+(y1-ys)*(y1-ys))
#print("xs = ", xs, "\nys = ", ys, "\nr = ", r)
xs = rounding(xs)
ys = rounding(ys)
r = complex_r(r)
#r = rounding(r)
#print("xs = ", xs, "\nys = ", ys, "\nr = ", r)
return equation(xs, ys, r)
#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. 19, 2016