# Projection matrix to project a point in a plane

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

Q = S P

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.

There's no matrix with this property; if there were, what would it do when multiplied by the coordinates of the point $L$?

If you represent points with homogeneous coordinates (i.e., append a "1" at the end of each coordinate triple), then there's a $4 \times 4$ matrix that'll do what you want...almost. It'll send $(P_x, P_y, P_z, 1)$ to a point $(R_x, R_y, R_z, R_w)$, with $R_y = 0$, that has the property that when you divide through by $R_w$, you get $(Q_x, Q_y, Q_z, 1)$, except when $R_w$ happens to be zero, as it will when you multiply it by the point $(L_x, L_y, L_z, 1)$.

The introduction to 2D and 3D transformations section of any computer graphics book will explain this in considerable detail.

• But how to determine it? – andrepcg Jun 11 '14 at 19:04
• Well...I could re-type 20 pages of my textbook, or you could go find any graphics text and read about it. Roughly speaking, pick four independent points in 3-space (I'd recommend 3 corners of a unit square in the xz-plane, like $(0,0,0,1)$, $(1, 0, 0, 1)$, and $(0, 0, 1, 1)$, plus a point on the $y$-axis like $(L_x, 1, L_z, 1)$ and write down what it means for the first three to be sent to scalar multiples of themselves, and for the fourth to be sent to exactly $(L_x, 0, L_z, 1)$. That'll constrain your matrix completely, so you can solve for the 16 entries in it. – John Hughes Jun 11 '14 at 20:13
• It's easier to start with the case where $L_x = L_z = 0$, find that matrix, and then tinker a little to handle the general case. – John Hughes Jun 11 '14 at 20:13