[Math] Projection matrix to project a point in a plane

geometrymatricesprojective-geometry

enter image description here

How to determinate the 4×4 S matrix so that the P gets projected into Q, on the XZ (Y=0) plane?

Q = S P

Best Answer

enter image description here

I've done done math and I have the solution now. This is simple similar triangles.

You have a light point L and a P point you want to project on the ground. If you draw the lines you find two triangles with the proportions. The red side divided by the green side is equivalent to the purple side divided by the pink side + green side like

$\frac{P_x - L_y}{P_y - L_y} = \frac{Q_x - L_x}{L_y}$

If you solve for $Q_x$ you have $Q_x = \frac{L_y \cdot P_x - L_x \cdot P_y}{P_y - L_y}$

The drawing is for 2D but don't forget we're on 3D so we need to solve for $Q_z$

$Q_z = \frac{-L_z \cdot P_y + L_y \cdot P_z}{P_y - L_y}$

We now want to find a matrix $M$ that gives the following result when multiplied by any point $P$ (The vertical axis is y and wee need a point on the floor so $y= 0$)

$ M *\begin{bmatrix}P_x\\P_y\\P_z\\1\\\end{bmatrix} = \begin{bmatrix}Q_x\\0\\Q_z\\1\\\end{bmatrix}$

The question here is to use homogeneous coordinates. If you look at $Q_x$ you have a division. There's no way to divide anything inside a matrix multiplication. So you use the homogeneous coordinate to get the result we want.

So we need a matrix $M$ multipled by any point $P$ that gives us $\begin{bmatrix} L_y \cdot P_x - L_x \cdot P_y\\ 0\\ -L_z \cdot P_y + L_y \cdot P_z\\ L_y-P_y\\ \end{bmatrix}$

and then we divide every row by $Py-Ly$ to get $\begin{bmatrix} \frac{L_y \cdot P_x - L_x \cdot P_y}{P_y-L_y}\\ 0\\ \frac{-L_z \cdot P_y + L_y \cdot P_z}{P_y-L_y}\\ 1\\ \end{bmatrix} $

$M = \begin{bmatrix} L_y & -L_x & 0 & 0\\ 0 & 0 & 0 & 0\\ 0 & -L_z & L_y & 0\\ 0 & -1 & 0 & L_y \end{bmatrix}$

Ps: I'm sorry if I'm not explaining the right way or if I'm making any mistake but the result is there.