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 bartorbard
import math
def bracketsRemove(inpution):
brackets = "(),"
for eachChar in inpution:
if eachChar in brackets:
inpution=inpution.replace(eachChar, "")
return inpution
def coordinatesX(inpution):
x = []
x.append(int(inpution[0:1]))
x.append(int(inpution[2:3]))
x.append(int(inpution[4:5]))
return x
def coordinatesY(inpution):
y = []
y.append(int(inpution[1:2]))
y.append(int(inpution[3:4]))
y.append(int(inpution[5:6]))
return y
def centreX(x1,x2,x3,y1,y2,y3):
centreX = 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)
return centreX
def centreY(x1,x2,x3,y1,y2,y3):
centreY = 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)
return centreY
def radius(x1, y1, centreX, centreY):
radi = ((x1-centreX)**2 + (y1-centreY)**2)
radi = math.sqrt(radi)
return radi
def roundedStr(roundDigit):
roundDigit2=(round(roundDigit,2))
rest = roundDigit2-(int(roundDigit))
if rest==0:
roundDigit2=int(roundDigit)
return str(roundDigit2)
def checkio(data):
inp = data
inp2 = bracketsRemove(inp)
x = coordinatesX(inp2)
y = coordinatesY(inp2)
x1 = x[0]
y1 = y[0]
x2 = x[1]
y2 = y[1]
x3 = x[2]
y3 = y[2]
x0=centreX(x1,x2,x3,y1,y2,y3)
y0=centreY(x1,x2,x3,y1,y2,y3)
R = radius(x1,y1,x0,y0)
x0 = roundedStr(x0)
y0 = roundedStr(y0)
R = roundedStr(R)
result = ("(x-"+x0+")^2+(y-"+y0+")^2="+R+"^2")
return result
#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. 27, 2016