[Math] Given an implicit 3D plane, how to find the orthogonal projection matrix – which projects any point – onto this plane

geometrylinear algebra

The plane is given by the equation $Ax+By+Cz+d = 0$. Can you tell me how can I figure out the 4×4 matrix which orthogonally projects any point given by homogeneous coordinates onto this plane?

I am using homogeneous coordinates, so a point is given by 4 values: $\vec{Q} = [xh,yh,zh,w]$, which in 3D space is $[xh/w, yh/w, zh/w]$.

Best Answer

I'll start by looking about how you can describe the projection of an arbitrary point $Q$ onto your plane, then derive a matrix notation from that.

Projecting a single point

The point $Q$ and its projection form a line which is perpendicular to the plane. All these perpendicular lines meet in a point $F=(A,B,C,0)^T$, which is the point at infinity orthogonal to your plane. A generic point on the line connecting $Q$ and $F$ can be described as a linear combination $Q+\lambda F$. (This inhomogenous formulation using a single parameter excludes $F$ itself, which is all right since $F$ will not be the projected point in any case.) Now you are looking for the point where this line connecting $F$ and $Q$ intersects the plane, i.e. $\left<Q+\lambda F,h\right>=0$, where $h=(A,B,C,D)^T$ is the vector describing your plane. This you can solve for $\lambda$:

$$\left<Q+\lambda F,h\right>=\left<Q,h\right> + \lambda\,\left<F,h\right>=0\\ \lambda=-\frac{\left<Q,h\right>}{\left<F,h\right>}$$

To avoid the division, you can also use a multiple of that point:

$$Q+\lambda F\;\sim\; \left<F,h\right>\,Q - \left<Q,h\right>F $$

This is the projection of a generic point $Q$.

Finding the matrix

If you assume the coordinates of $Q$ to be variables, then the coordinates of the result will be linear in these variables, so you can interpret the whole operation as a linear map and therefore write it as a matrix. You can also find the formula of that matrix like this:

$$ \left<F,h\right>\,Q - \left<Q,h\right>F = \left<F,h\right>\mathbb 1\cdot Q - Fh^T\cdot Q = \left(\left<F,h\right>\mathbb 1 - Fh^T\right)Q \\ = \begin{pmatrix} B^{2} + C^{2} & -A B & -A C & -A D \\ -A B & A^{2} + C^{2} & -B C & -B D \\ -A C & -B C & A^{2} + B^{2} & -C D \\ 0 & 0 & 0 & A^{2} + B^{2} + C^{2} \end{pmatrix}\cdot Q $$

If anyone reading this post should be interested in central instead of orthogonal projection, simply use that center of projection as $F$, and the above formula will help you compute the matrix for that as well.