1. 基础知识
这里的立体几何基础理论详细见参考资料
2. 手动推导
这个问题其实可以简化为,点P在任意平面上的投影坐标,推导过程如下所示:
总结:根据坐标(x0, y0, z0),即可求出参数t,随后便可求出在新平面上的投影坐标
3. 代码验证
参考代码:
""" 代码功能: 将3d点云投影到xyz等不同平面上 """ import numpy as np import mayavi.mlab as mlab # 参数说明: # - points:点云数据 # - flat:3d平面的参数,Ax+By+Cz+D=0,参数即为(A,B,C,D) # xy平面:(0 0 1 0) | xz平面:(0 1 0 0) | yz平面:(1 0 0 0) def project_2d(points, flat): # 点云投影平面 A, B, C, D = flat distance = A**2 + B**2 + C**2 t = -(A*points[:, 0] + B*points[:, 1] + C*points[:, 2] + D)/distance x = A*t + points[:, 0] y = B*t + points[:, 1] z = C*t + points[:, 2] project_point = np.array([x, y, z]).T print(project_point.shape) # 投影展现 mlab.figure(bgcolor=(0, 0, 0), size=(640, 640)) mlab.points3d(x, y, z, y, mode='point', colormap='spectral') mlab.show() if __name__ == '__main__': txt_path = r"E:\workspace\PointCloud\Pointnet2\data\modelnet40_normal_resampled\airplane\airplane_0001.txt" points = np.loadtxt(txt_path, delimiter=',') project_2d(points, (0, 0, 1, 0))
- 1)在xy平面上的投影
project_2d(points, (0, 0, 1, 0)) mlab.points3d(x, y, z, y, mode='point', colormap='spectral')
结果展示:
- 2)在xz平面上的投影
project_2d(points, (0, 1, 0, 0)) mlab.points3d(x, y, z, x, mode='point', colormap='spectral')
结果展示:
- 3)在yz平面上投影
project_2d(points, (1, 0, 0, 0)) mlab.points3d(x, y, z, y, mode='point', colormap='spectral')
结果展示:
ps:这里的平面设置可以是任意平面,点云可以在任意平面上投影
参考资料:
1. python三维点云投影(一)