# Can someone explain homogeneous coordinates in the context of computer graphics?

## Recommended Posts

I have to admit that I have never used them and do not fully understand them or why they are used. I did a Google search, but I turned up more math than practical explanations and examples. I'm just lost as to both how and why this projects a 3D vertex onto a 2D plane: x' = x / w; y' = y / w; z' = z / w; In most cases that I've seen, 'w' equals 1.0 or 0.0. Not only that, but to project a 3D vertex into 2D screen coordinates, don't you have to divide by z? When and how does z factor in? If w is the depth coordinate, why not replace it with z and go back to (x,y,z) coordinates? This whole process mystifies me. The "Poor man's projection" is so much more clear and easy to understand. However, if this is the way it is done now, I'd really like to know the basics behind it. Can someone explain this in detail? A small code example showing projections of 3D vertices onto the screen would be nice, if possible.

##### Share on other sites
The operation you give there doesn't project a 3D vertex onto a 2D plane. It projects a 4D homogeneous point onto the 3D hyperplane w=1. To actually apply the camera perspective you first need to apply a perspective transform matrix (see last paragraph).

Homogeneous coordinates really just allow infinitely far ("ideal") points to be represented. Working in a space that supports these allows you to perform linear transforms in 4D (or one dimension up, generally) that map to non-linear transforms in 3D (or one dimension lower, generally), once the division by w is performed. For example, if you shear x, y and z against w in the "4D" homogeneous space, you affect a translation in "3D" (quotes are used since a point in such a homogeneous space is not technically 4D, since all points are the same to multiples by a positive scalar).

The "perspective transform" matrix that is commonly used (google for it) is also not actually a projection. It performs a 4D linear transform that warps the space so that points near the view plane scale larger in X and Y than points at the far plane, effectively warping a frustum into a cuboid. A true projection (one that is idempotent) would lose the depth information, whereas this sort of transform retains it for use in the z-buffer (or w-buffer). The actual true projection then comes in afterwards by simply ommitting the z-value when rasterizing the triangle on 2D (although the z-value is still interpolated over the z-buffer).