通过 2d 横截面的圆柱体拟合

cyilnder fitting through 2d cross sections

我正在尝试开发一个 python 代码来从点云重建 3D 几何基元。我从气缸开始。我应该通过切片来处理。所以现在我有一组二维横截面。我在提取的轮廓上安装了圆圈。但我不知道如何安装一个穿过我拥有的 cicles 的圆柱体。谁能帮帮我。 PS:我是 Python 的新手 谢谢 enter image description here

我已经通过在拟合圆的中心拟合一条线解决了这个问题。这代表我的圆柱体的轴,我的半径是横截面半径的平均值。我仍然需要找到我的圆柱体的确切高度。

fit_data = []
Rad = []
##

for i in range (len(C)):

    data= C[i][0]
    xc,yc,r,s = cf.least_squares_circle(data)
    fit_data.append([xc,yc,data[0,2]])
    Rad.append(r)
    cf.plot_data_circle(data[:,0], data[:,1],xc,yc,r)
fit_data=np.array(fit_data) 
print(fit_data,"\n radius =", Rad)
Center = np.mean(fit_data, axis=0)

R = np.mean(Rad)

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.set_xlim3d(0, 120)
ax.set_ylim3d(0,120)
ax.set_zlim3d(0,120)
ax.add_collection3d(Poly3DCollection(m.vectors, facecolors='y', linewidths=1, alpha=0.2))
ax.scatter(fit_data[:,0], fit_data[:,1], fit_data[:,2], c='blue')
ax.scatter(verts[:,0], verts[:,1], verts[:,2], c='y')


datamean = fit_data.mean(axis=0)

# Do an SVD on the mean-centered data.
uu, dd, vv = np.linalg.svd(fit_data - datamean)

# Now vv[0] contains the first principal component, i.e. the direction
# vector of the 'best fit' line in the least squares sense.

# Now generate some points along this best fit line, for plotting.


linepts = vv[0] * np.mgrid[-60:60:2j][:, np.newaxis]

# shift by the mean to get the line in the right place
linepts += datamean
ax.plot(linepts[:,0], linepts[:,1], linepts[:,2], 'r', label = 'fitted axis')

ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
ax.legend()

plt.show()

print ("Mean Radius=", R , "\n Center = " , Center)