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 mehWincenty
def checkio(data):
string = ""
for i in data :
if i != "(" and i != ")" :
string += i
l = string.split(',')
x1 = int(l[0])
y1 = int(l[1])
x2 = int(l[2])
y2 = int(l[3])
x3 = int(l[4])
y3 = int(l[5])
d = (x1-x2)*(y2-y3)-(x2-x3)*(y1-y2)
u = (x1**2-x2**2+y1**2-y2**2)/2
v = (x2**2-x3**2+y2**2-y3**2)/2
a = (u*(y2-y3)-v*(y1-y2))/d
b = (v*(x1-x2)-u*(x2-x3))/d
c = ((x1-a)**2 + (y1-b)**2)**0.5
string = "(x-" + ('%.2f' % a).rstrip('0').rstrip('.') + ")^2+(y-" + ('%.2f' % b).rstrip('0').rstrip('.') + ")^2=" + ('%.2f' % c).rstrip('0').rstrip('.') + "^2"
return string
#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. 11, 2016
Comments: