Written by Colin+ in ask uncle colin, matrices.

*Ask Uncle Colin* is a chance to ask your burning, possibly embarrassing, maths questions -- and to show off your skills at coming up with clever acronyms. Send your questions to colin@flyingcoloursmaths.co.uk and Uncle Colin will do what he can.

Dear Uncle Colin,

I'm working on a (3D) computer graphics course, and my notes have some equations in that I don't understand. I have a point light at (4D) position $\vec L$, an object translated by a 4D matrix $\bb M$ and a (4D) point on the surface at $\vec p$, as measured from the object's centre. I want to know the (4D) direction vector $\vec w$ of the light.

My notes say it's $\vec w = \vec L - \bb M \vec p$, but it might as well be Greek!

A Ray? It's Simple To Obtain The Light Equations

The first thing to clear up, ARISTOTLE, for regular readers of Ask Uncle Colin, is what on earth all this 4D stuff has to do with a 3D set-up. It's actually quite a neat trick: if you extend your three dimensions into four, and call the fourth component always 1, it means you can represent *translations* using a matrix, as well as the traditional enlargements, reflections, rotations, shears and so on -- at the cost of an extra coordinate, all of the transformations you're likely to need become linear, and you don't need to mix multiplying and adding matrices.

For example, to translate the point $(1, 2, 3)$ by the vector $(-4, 5, -6)$, you would represent the point as the vector $(1, 2, 3, 1)^T$ and the translation as the matrix

$\left( \begin{array}{cccc} 1 & 0 & 0 & -4 \\ 0 & 1 & 0 & 5 \\ 0 & 0 & 1 & -6 \\ 0 & 0 & 0 & 1 \end{array} \right)$

(it's the identity matrix with the vector to be translated by as the top three elements of the final column).

Multiplying this by the vector gives you the vector $(-3, 7, -3, 1)^T$, which corresponds to the point $(-3, 7, -3)$, as required.

Ah, I thought you'd never ask.

If we knew where the point (let's call it $\vec x$) was with respect to the origin $O$, we could immediately work out the direction of the light from the point: it's simply $\vec L - \vec x$. (You travel to the origin backwards along $\vec x$ and then to the light forwards along $\vec L$ -- but rather that $-\vec x + \vec L$, we prefer to write $\vec L - \vec x$ for reasons of neatness.

We're nearly there! Where is the point, exactly? It would be at the point $\vec p$ if we hadn't transformed it, but the transformation moves it to $\bb M \vec p$. If we replace the $\vec x$ by that, we get:

$\vec w = \vec L - \bb M \vec p$, as your notes say.

-- Uncle Colin