29

Lets say I have point (x,y,z) and plane with point (a,b,c) and normal (d,e,f). I want to find the point that is the result of the orthogonal projection of the first point onto the plane. I am using this in 3d graphics programming. I want to achieve some sort of clipping onto the plane.

DogDog
  • 4,820
  • 12
  • 44
  • 66

2 Answers2

61

The projection of a point q = (x, y, z) onto a plane given by a point p = (a, b, c) and a normal n = (d, e, f) is

q_proj = q - dot(q - p, n) * n

This calculation assumes that n is a unit vector.

antonakos
  • 8,261
  • 2
  • 31
  • 34
3

I've implemented this function in Qt using 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;
}
Fernando
  • 1,477
  • 2
  • 14
  • 33
  • 2
    This uses the same algorithm as the previous, accepted answer and uses a language not asked for. Just what does this answer add to the accepted answer? – Rory Daulton Jun 01 '17 at 22:35