The title asks it all, and could someone please also explain the formula as well? Thanks.

  • 4
    $\begingroup$ short answer : divide by $z$. If $x$ is horizontal, $y$ vertical and $z$ the distance orthogonal to the screen (from your eye) then coordinates will be $s\cdot \frac xz$ and $s\cdot \frac yz$ with $s$ a scaling factor proportional to (say) vertical resolution of screen. This because an object $n$ times farther will appear $n$ times smaller (or because you compute the intersection of every line from your eye to the screen plane). $\endgroup$ Mar 11 '12 at 9:48
  • $\begingroup$ en.wikipedia.org/wiki/3D_projection#Perspective_projection $\endgroup$
    – user856
    Aug 28 '13 at 3:45

Projection has two components: the model and the camera. The camera has two parts, the focal point and the image plane. The model is what you're looking at. The focal point is a point, and the image plane is a plane not containing it.

To project a point onto the plane, we simply draw a line segment between it and the focal point, and record where it intersects with the image plane. To make things easy, we'll put the camera in standard position: focus is at $\langle 0, 0, 0 \rangle$, and the image plane is $z = 1$. This makes projection nearly trivial: $\langle x, y, z \rangle$ projects to $\langle \frac{x}{z}, \frac{y}{z}, 1 \rangle$. This is referred to as a perspective divide. [I'll put up a picture in a bit]

This is only practical if your camera and image plane are in that configuration to begin with. So, typically, matrix transforms are used to move the model, not the camera.

Since these translations often require translation, simple $3 \times 3$ matrices won't suffice. Any such matrix will fix the origin (linear transform), which is not what we want (affine transform). Instead, we use homogeneous coordinates. There are four coordinates, $x$, $y$, $z$ and $w$, not all zero. We say that scalar multiples of these are equivalent, that is: $[x, y, z, w] \sim [\lambda x, \lambda y, \lambda z, \lambda w]$, for all $\lambda \ne 0$. This allows us to use $4 \times 4$ matrices for transformations. For example, this matrix translates by $\langle a, b, c \rangle$.

$$ \left[ \begin{matrix} 1 & 0 & 0 & a \\ 0 & 1 & 0 & b \\ 0 & 0 & 1 & c \\ 0 & 0 & 0 & 1 \\ \end{matrix} \right] \left[ \begin{matrix} x \\ y \\ z \\ 1 \\ \end{matrix} \right] = \left[ \begin{matrix} x + a \\ y + b\\ z + c\\ 1 \\ \end{matrix} \right] $$

In general, we put any reflections or rotations in the upper left corner, and translations in the upper right. Let $T$ be a $3 \times 3$ matrix representing a linear transformation, and $A$ be a $3$-vector for translation. $v$ is the vector we are transforming.

$$ \left[ \begin{matrix} T & A \\ 0 & 1 \\ \end{matrix} \right] \left[ \begin{matrix} v \\ 1 \\ \end{matrix} \right] = \left[ \begin{matrix} Tv + A \\ 1 \\ \end{matrix} \right] $$

It is clear, we have transformed our vector linearly, then translated it. Now, all the transformations we needed are just matrices. So we can multiply them together, and get just one $4 \times 4$ matrix. Conveniently, we can also represent perspective divides as a matrix, giving us just one matrix for projection!

$$ \left[ \begin{matrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 1 & 0 \\ \end{matrix} \right] \left[ \begin{matrix} x \\ y \\ z \\ 1 \\ \end{matrix} \right] = \left[ \begin{matrix} x \\ y \\ z \\ z \\ \end{matrix} \right] \sim \left[ \begin{matrix} x/z \\ y/z \\ 1 \\ 1 \\ \end{matrix} \right] $$

We end up with just one matrix that transforms a point into position, then projects it onto the image plane.

Note: This part is more computer programming than math, but it's useful anyway. If $w$ is non-zero, we can divide through by it to get an equivalent set of coordinates with $w = 1$. So there are only two types of coordinates: $w = 1$ and $w = 0$. We use the former for points, because translations affect them, and the latter for vectors, because they don't. For example, try using the translation matrix above on $[x, y, z, 0]$. Is this behavior what we expect from a vector? Try a rotation matrix ($4 \times 4$) on both. Why does this affect them in the same way?


yes, where x,y,z 3d coordinates with z being depth x',y' 2d coordinates maxx', minx', maxy', miny' are the limits of the screen maxx and maxy are the maxium distance displayed on the screen at z=0 Cz= a constant to multiple z so infinite is at the center

x'= x/maxx * ((maxx'-minx')/(2^z*Cz)) + (maxx'- maxx/2^z*Cz)/2 y'= y/maxy * ((maxy'-miny')/(2^z*Cz)) + (maxy'-maxy'/2^z*Cz)/2

a screen 100*100 max of 10 miles Cz=1, so at an infinite point, x,y=(50,50)


This site is temporarily in read only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .