Search code examples
pythonmath3dlinear-algebraprojection

Formula to project a vector onto a plane in the direction of another vector


My aim is to take a vector v in 3D space, project it onto a provided plane P with normal N, but do so along a direction vector D.

That is, I would like to obtain an oblique (non-orthogonal) projection of of a point onto a plane.

I've reviewed this question but using the formula with some simple example values results in a poor output with denominator of 0, I feel as I'm having a conceptual mishap.

The image below describes the problem. Diagram in 3D


Solution

  • n•p = n•w (siince p and w are both in the plane)
    = n•(v + kD)
    = n•v + kn•D
    kn•D = n•(p - v)
    k = n•(p - v) / (n•D)
    w = v + (n•(p - v) / (n•D))D