计算由三个给定点构成的圆的半径和中心坐标(x,y)

时间:2019-05-16 22:11:08

标签: python

我需要您解释下面的代码背后的数学原理。 s,px和py是什么,通常,我们遵循什么逻辑在这里找到答案?

print("Input three coordinate of the circle:")
x1, y1, x2, y2, x3, y3 = map(float, input().split())
c = (x1-x2)**2 + (y1-y2)**2
a = (x2-x3)**2 + (y2-y3)**2
b = (x3-x1)**2 + (y3-y1)**2
s = 2*(a*b + b*c + c*a) - (a*a + b*b + c*c) 
px = (a*(b+c-a)*x1 + b*(c+a-b)*x2 + c*(a+b-c)*x3) / s
py = (a*(b+c-a)*y1 + b*(c+a-b)*y2 + c*(a+b-c)*y3) / s 
ar = a**0.5
br = b**0.5
cr = c**0.5 
r = ar*br*cr / ((ar+br+cr)*(-ar+br+cr)*(ar-br+cr)*(ar+br-cr))**0.5
print("Radius of the circle:")
print("{:>.3f}".format(r))
print("Central point coordinates (x, y) of the circle:")
print("{:>.3f}".format(px),"{:>.3f}".format(py))

0 个答案:

没有答案