Homogeneous Coordinates Make for Easy Rays

This is a bit of a basic observation, but I figured I’d write it down nonetheless.

Suppose you have a transformation matrix in the usual 4×4 form. You transform a point by multiplying the matrix with the vector (in whatever order is conventional for you). Before doing this, you need to convert your point into homogeneous coordinates by adding an extra “1” to the end as the W coordinate. This works great.

But sometimes you need to be able to manipulate pure directions. For example, you’re transforming normal vectors. In this case, you care about rotation and the sign of the scale, but don’t care about the magnitude of the scale, and translation must be excluded. You could do this by first removing the translation from the transformation matrix by changing the last column back to (0, 0, 0, 1)… or, you could do it instead by using 0 as the W coordinate when converting to homogeneous coordinates.

This may seem like a hack, but it’s well-grounded and anything but a hack. 0 as the W coordinate turns the vector into an “infinite-length” vector pointed in a certain direction. Rotations will surely change the direction, as will negative scaling. But scaling infinity by a positive constant still yields infinity, and trying to add any finite value to infinity will be insignificant compared to the infinity, so translations and useless scales naturally fall out.

Fun fact: While projective spaces are quite natural in 3D graphics, I first encountered them when studying elliptic curves. When used in cryptography, there is only one point at infinity, and it functions as the identity element when the curve is interpreted as a group.

Tags: ,

Leave a Reply