通过二维横截面进行青铜接头

问题描述 投票:0回答:1

我正试图开发一个python代码,从点云重建3D几何基元。我从圆柱体开始。我应该通过切片来处理。所以现在我有一组二维截面。我已经将圆圈拟合到提取的轮廓上。但我不知道如何拟合一个穿过我所拥有的圆柱体的圆柱体。谁能帮帮我,请。PS:我是Python的初学者,thx。请在此输入图片描述

python curve-fitting point-clouds 3d-reconstruction
1个回答
0
投票

我已经解决了这个问题,将一条线拟合到拟合圆的中心。这代表了我的圆柱体的轴线,我有raduis,这是横截面陶瓷的raduis的平均值。但我仍然需要找到我的圆柱体的确切高度。

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)   
© www.soinside.com 2019 - 2024. All rights reserved.