checkio exercise

计算三角形外接圆的函数:
def circle(note):
    note = list(eval(note))
    x1 = note[0][0]
    x2 = note[1][0]
    x3 = note[2][0]
    y1 = note[0][1]
    y2 = note[1][1]
    y3 = note[2][1]
    x=((y2-y1)*(y3*y3-y1*y1+x3*x3-x1*x1)-(y3-y1)*(y2*y2-y1*y1+x2*x2-x1*x1))/(2*(x3-x1)*(y2-y1)-2*((x2-x1)*(y3-y1)))
    y=((x2-x1)*(x3*x3-x1*x1+y3*y3-y1*y1)-(x3-x1)*(x2*x2-x1*x1+y2*y2-y1*y1))/(2*(y3-y1)*(x2-x1)-2*((y2-y1)*(x3-x1)))
    a = ((x2-x3)**2+(y2-y3)**2)**0.5
    b = ((x1-x3)**2+(y1-y3)**2)**0.5
    c = ((x2-x1)**2+(y2-y1)**2)**0.5
    p = 0.5*(a+b+c)
    s = (p*(p-a)*(p-b)*(p-c))**0.5
    r = (a*b*c)/(4*s)
    x = round(x,2)
    y = round(y,2)
    r = round(r,2)
    return print(x,y,r)

猜你喜欢

转载自www.cnblogs.com/bladeofstalin/p/9099039.html