Python 3.x 脚本以确定具有不同轨迹的多个圆的相同中心点
我的计划中有许多圆圈轨迹;这些圆的中心相同。Python 3.x 脚本以确定具有不同轨迹的多个圆的相同中心点,python-3.x,Python 3.x,我的计划中有许多圆圈轨迹;这些圆的中心相同。 如何使用python脚本确定此中心点 import random, import numpy as np, import matplotlib.pyplot as plt def find_circle_center():##script I need to know x,y=[],[] #make circle center with somme error _circle = np.random.multivariate_normal
如何使用python脚本确定此中心点
import random, import numpy as np, import matplotlib.pyplot as plt
def find_circle_center():##script I need to know
x,y=[],[] #make circle center with somme error
_circle = np.random.multivariate_normal([0, 0], [[10, 0],[0, 10]], 1)[0]
circle_x = _circle[0]
circle_y = _circle[1]
# angle
alpha = np.linspace(0,2 * pi,10001)
# many radius trajectory
for radius in [1,10,100,200,300,400,500,600]:
aux = random.randint(0,10000)
alpha_aux = np.concatenate([alpha[aux:,],alpha[:aux,]]) #randomize angle array
_x = radius * np.cos(alpha_aux) + circle_x
_y = radius * np.sin(alpha_aux) + circle_y
x.append(_x)
y.append(_y)
x,y=np.array(x),np.array(y) #now i have points of circles trajectories.
_xc,_yc = [],[]
#this loop is to know after how many points will converge to the good answer
for j in range(2,1001,1):
xc,yc = find_circle_center(x[:,:j].ravel(), x[:,:j].ravel())
_xc.append(xc)
_yc.append(yc)
_xc,_yc = np.array(_xc),np.array(_yc)
plt.plot(range(2,1001,1),np.sqrt(_xc**2 +_yc**2))
plt.show()
圆的圆心也是它的质心,在那个圆上。如果有一组点表示某种圆,只需将它们平均在一起,该点将是圆心的最佳近似值。如果圆是完整的,这是正确的。但不适用于不完整的圆;示例:角度θ中的圆弧,你不能像这样找到中心,但通过拟合是的。这就是为什么在我的代码中,我在每次估计中改变点数,以找到最佳分辨率的角度,或者每个圆中的点数以获得最佳分辨率。现在我尝试研究Hough变换。