Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Three Points Circle solution in Clear category for Three Points Circle by Seaclaid
def checkio(data):
circle=''
data=tuple(data)
x1,y1,x2,y2,x3,y3=data[1],data[3],data[7],data[9],data[13],data[15]
x1=int(x1)
y1=int(y1)
x2=int(x2)
y2=int(y2)
x3=int(x3)
y3=int(y3)
odp=[0,0,0]
odp[0] = 0.5 * (x2 * x2 * y3 + y2 * y2 * y3 - x1 * x1 * y3 + x1 * x1 * y2 - y1 * y1 * y3 + y1 * y1 * y2 + y1 * x3 * x3 + y1 * y3 * y3 - y1 * x2 * x2 - y1 * y2 * y2 - y2 * x3 * x3 - y2 * y3 * y3) / (y1 * x3 - y1 * x2 - y2 * x3 - y3 * x1 + y3 * x2 + y2 * x1)
odp[1] = 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)
odp[2]=(((x1-odp[0])**2)+((y1-odp[1])**2))**.5
print(odp)
for i in range(3):
if odp[i]==int(odp[i]) or int(odp[i])==round(odp[i],2):
odp[i]=int(odp[i])
else:
odp[i]=round(odp[i],2)
circle='(x-'+str(odp[0])+')^2+(y-'+str(odp[1])+')^2='+str(odp[2])+'^2'
print(circle)
return circle
#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"
assert checkio("(7,3),(9,6),(3,6)") == "(x-6)^2+(y-5.83)^2=3^2"
Jan. 14, 2017