## Homogeneous coordinates

Did you know about homogeneous coordinates? I had to use them while programming something and it turns out they’re pretty interesting, at least for nerds like me. They are a mathematical concept for dealing with spaces that contain points at infinity, and have other useful properties. In fact, Euclidean spaces are a subset of homogeneous space.

Parallel rails: clearly separate close to the observer, but do they cross each other at infinite distance? (Let’s ignore for the moment that there’s a bend in the track further down the line!) Attribution: Tomasz Sienicki [CC-BY-SA-3.0], via Wikimedia Commons

The train track above has parallel rails, but if you look along the track you see the rails converging. How far away do they converge? If you got an impossible (non-diffraction-limited) telescope and looked further and further down the line, you would find that they never cross, but seem to be getting closer and closer together from the perspective of the observer. In normal Euclidean space (points represented by coordinates x, y, z, whatever) the parallel tracks appear to cross at infinity ($$\infty$$).

Points at infinity are pretty useless for calculations. If you were to take the space on which the tracks were defined and stretch it uniformly in all directions, the point at $$\left( \infty, \infty \right)$$ would not change: $$2\infty$$ is still just $$\infty$$. The relationship between the non-infinity and infinity points in your space would warp.

Homogeneous coordinate systems get around this problem by introducing an additional coordinate. Instead of the Euclidean $$\left(x, y\right)$$ coordinates, you have $$\left(x’, y’, w\right)$$. Here, $$x$$ is related to $$x’$$ by $$x = \frac{x’}{w}$$ (and $$y = \frac{y’}{w}$$). Now the infinities are gone, because you can represent infinity in homogeneous coordinates by using $$w = 0$$ (because anything divided by $$0$$ approaches infinity).

So what? Well, it turns out that homogeneous coordinates have a useful property. The homogeneous coordinate $$\left(1, 2, 3\right)$$ in Euclidean space is $$\left(\frac{1}{3}, \frac{2}{3}\right)$$. Doubling the homogeneous coordinate to $$\left(2, 4, 6\right)$$, the equivalent Euclidean point is still $$\left(\frac{1}{3}, \frac{2}{3}\right)$$. Homogeneous coordinates are scale invariant, meaning that stretching or squeezing the space in a uniform way does nothing to the relationship between points defined on that space. This is useful for CAD applications and other types of 3D modelling where you might try to fit some projection of a 3D surface (e.g. a sphere) onto a 2D plane (e.g. a computer screen).

At some point you will still have to display your space in Euclidean coordinates so your eyes or your computer monitor can see/display it, and then the infinities come back and you see again the effects of perspective. But homogeneous coordinates allow you to scale and rotate sets of points without losing the relationship between those points.