The One-Line Math Trick Behind Every 3D Camera

Divide by Depth for Instant 3D

The One-Line Math Trick Behind Every 3D Camera

A personal journey from treating cameras as black boxes to understanding the simple math behind 3D projection. The core trick—dividing x and y by z—is shown to be a special case of the perspective projection matrix, which adds field of view, aspect ratio, and clipping planes. The full pipeline from world space to pixels is demystified.

In essence, if we say y is up and z is forward, 3D coordinates (x, y, z) can be projected into 2D coordinates (x', y') by dividing x and y by z.
  1. tmoertel

    The explanation of "What's that extra 1 for?" in the column representation of 3-d coordinates (x y z 1) could benefit from mentioning that translation—moving things—is not a linear transformation (the origin is not mapped to itself) but an affine transformation. Therefore, you cannot represent translation in 3-d space with a 3x3 matrix. What you can do, though, is embed that 3-d space within a 4-d space fixed at some coordinate on its 4th dimension, typically w=1. Then, a translation in the original 3-d space can be represented as a linear transformation in the 4-d space and thus can also be represented by a 4x4 matrix multiplication. So the extra 1 is actually what allows all common 3-d operations, including translation, to be done via linear algebra and thereby harness the brutal power of matrix multiplication on modern computing devices.

  2. aappleby

    FWIW, if you start with "The view frustum is a 90 degree pyramid with the tip cut off at z = 1 and the 'end' at infinity", you can then work out how to map that to a NDC using a matrix and perspective divide.

    I've used that when teaching short "Graphics 101" (not in the first session though) and the math comes out more intuitive than the usual "here's how to calculate a perspective matrix, don't ask where these numbers come from" version.

  3. lolakutty

    Trust me, I am not very bright. But as boy with a 486 in the mid 90s, I was so inspired, a that I figured this out without the internet (was still unheard of) or the books.

    I still remember the rush that I got when I got the rotating cube in my QBasic IDE in my 14inch monochrome monitor. The intuition I used was derived from how light casted shadows of 3d objects in a 2d wall..From there, this x' = x/z

    y' = y/z, follows naturally..

  4. gabrieloc

    Hi! I wrote a few notes on how 3D cameras work with interactive examples to hopefully demystify a pretty complex topic that I once struggled with. Maybe this is useful for someone here, and if not, there are fun sliders to play with!

  5. rhyperior

    At one point all of this seemed like common knowledge in software because Carmack, Abrash and Hecker (among many others) were working in the open on games and discovery. Kind of funny that someone had to reinvent from first principles!

More from this day

2026-09-21