假设我有点(x,y,z),平面有点(a,b,c)和法向量(d,e,f)。我想找到第一个点在平面上正交投影的结果点。我正在使用这个方法进行3D图形编程,希望实现一些对平面的剪切。
给定点q = (x, y, z)
在由点p = (a, b, c)
和法向量n = (d, e, f)
确定的平面上的投影为
q_proj = q - dot(q - p, n) * n
这个计算假设 n
是一个单位向量。
我使用Qt和QVector3D实现了这个函数:
QVector3D getPointProjectionInPlane(QVector3D point, QVector3D planePoint, QVector3D planeNormal)
{
//q_proj = q - dot(q - p, n) * n
QVector3D normalizedPlaneNormal = planeNormal.normalized();
QVector3D pointProjection = point - QVector3D::dotProduct(point - planePoint, normalizedPlaneNormal) * normalizedPlaneNormal;
return pointProjection;
}