点向平面投影
点向平面投影
·
算法原理:

1.求平面上的点到平面外上的点的方向向量:
v = point-orig(在每个维度中);
2.将该矢量的点与单位法向量n点乘求得投影距离:
dist = vx*nx + vy*ny + vz*nz;dist #点到平面的距离
3.将单位法向量乘以距离,然后将平面外的点减去该向量从而求得投影点。
projected_point = point -dist*normal;
上图中:红色为v;dist是蓝色和绿色的长度,等于v点乘normal。蓝色是normal*dist。绿色与蓝色相同,它们只是在不同的地方绘制。要找到Planar_xyz,请从点开始,然后减去绿色向量。
代码实现:
import numpy as np
point_in_plane = np.array([0, 0, 0])
normal_in_plane = np.array([0, 13, 1])
points = np.array([1, 1, 1])
def ProjectPointsToPlane(point_in_plane, normal_in_plane, points):
v = points - point_in_plane
normalized_normal_in_plane = normal_in_plane / np.linalg.norm(normal_in_plane)
dist = v.dot(normalized_normal_in_plane)
projected_points = (points - dist * normalized_normal_in_plane)
return projected_points
ProjectPointsToPlane(point_in_plane, normal_in_plane, points)
更多推荐



所有评论(0)