The Master Space to View Space Map

by William Shoaff with lots of help


Contents

Preliminary Ideas About Perspective Space

Given a point in view space we want to project it along projection lines (projectors) that meet at a center of projection

\begin{displaymath}C=(x_c,\,y_c,\,z_c).\end{displaymath}

This produces an image similar to camera lens (or cyclops). We will find that straight lines do not remain straight, so the map is non-linear and can not represent with a matrix, except by fudging.

Let's pretend we're given a projection plane

\begin{displaymath}ax+by+cz+d=(x,\,y,\,z,\,1)\cdot \left(\begin{array}{c}a \\ b\\ c\\ d\end{array}\right)=0.\end{displaymath}

and that $O=(x_o,\,y_o,\,z_o)$ is object point in view space to be projected onto the projection plane toward the center of projection C.

The parametric equation of the line from $(x_o,\,y_o,\,z_o)$ to $(x_c,\,y_c,\,z_c)$ is given by

\begin{eqnarray*}x & = & x_o + (x_c-x_o) t\\
y & = & y_o + (y_c-y_o) t\\
z & = & z_o + (z_c-z_o) t\\
\end{eqnarray*}


or

\begin{eqnarray*}(x,\,y,\,z) & = & (x_o,\,y_o,\,z_o) + (x_c-x_o,\,y_c-y_o,\,z_c-z_o)t\\
(x,\,y,\,z) & = & O + (C-O)t\\
P & = & O(1-t) + Ct\\
\end{eqnarray*}


where $P=(x,\,y,\,z)$.

We want to find the point P along this line which also lies in the projection plane. Thus, substitute the parametric line equation into plane equation and solve for the parameter t, which yields the value where the line intersects the plane.

\begin{eqnarray*}0 & = & ax+by+cz+d \\
& = & a(x_o+(x_c-x_o)t) +b(y_o+(y_c-y_o...
...\frac{ax_o + by_o +cz_o +d}{a(x_c-x_o) + b(y_c-y_o) +c(z_c-z_o)}
\end{eqnarray*}


Or a little neater, if we use homogeneous coordinates:

\begin{displaymath}P=(x,\,y,\,z,\,1),\,O=(x_o,\,y_o,\,z_o,\,1),\,C=(x_c,\,y_c,\,z_c,\,1)\end{displaymath}

for the points and $\vec{N}=(a,\,b,\,c,\,d)$ for the plane coefficients,

\begin{eqnarray*}0 & = & \langle \vec{N}\cdot P\rangle \\
& = & \langle \vec{N...
...gle \vec{N}\cdot O\rangle}{\langle \vec{N}\cdot (O-C)\rangle}\\
\end{eqnarray*}


Note this is well defined, unless $\langle \vec{N}\cdot (C-O)t\rangle=0$, which only happens when the projection line from O to C is parallel to the projection line (projector).

Now know t we can calculate the projected point where the projector intersects the projection plane.

\begin{eqnarray*}P & = & O + (C-O)t\\
& = & O + (C-O)\frac{\langle \vec{N}\cdo...
...e \vec{N}\cdot C\rangle}%
{\langle \vec{N}\cdot (O-C)\rangle}\\
\end{eqnarray*}


Note denominator for P depends on object point $O=(x_o,\,y_o,\,z_o)$, and thus this transformation can not be represented via a matrix transformation. However, we could compute

\begin{displaymath}P\langle \vec{N}\cdot (O-C)\rangle\end{displaymath}

by a matrix transform and the perform a homogeneous divide to obtain the projected point P.

A Special (Usual) Case

Pretend the projection plane is z=0 in view space, that is the plane in which the eye or camera lens lies. Place the center of project at a positive distance along the view space z axis, that is at $C=(0,\,0,\,d)$. From the previous equation for t, using $\vec{N}=(0,\,0,\,1,\,0)$we find t=-zo/(d-zo), and

\begin{eqnarray*}x_p & = & x_o + (0-x_o) t = \frac{dx_o}{d-z_o} \\
y_p & = & y_...
...-y_o) t = \frac{dy_o}{d-z_o}\\
z_p & = & z_o + (d-z_o) t = 0\\
\end{eqnarray*}


Or by similar triangles

\begin{eqnarray*}\frac{x_p}{-d} & = & \frac{x_o}{z_o-d} \\
\frac{y_p}{-d} & = & \frac{y_o}{z_o-d} \\
z_p & = & 0 \\
\end{eqnarray*}




To summarize,

A Perspective Projection Example

Types of Perspective Projections

The View Space to Perspective Space Map

The above discussion, while useful, does not tell us how we really want to approach the view space to perspective space transformation via a computer implementation of the perspective map. To do so, let's pretend the view volume, in view coordinates, we want to map is specified by view angle

\begin{displaymath}0 < \alpha < \pi\end{displaymath}

and near and far clipping planes

\begin{displaymath}z = z_n \quad \mbox{and} \quad z = z_f\end{displaymath}

This defines a view frustum (a truncated pyramid), as shown in Figure 1. We want to map the view frustum into a rectangular box

\begin{displaymath}-1\leq x \leq 1,\,-1\leq y \leq 1,\,0\leq z \leq 1.\end{displaymath}

Note although we call the near and far planes clipping planes we do not necessarily have to clip against them. However, it may make sense to clip objects that are so far from our eye that they appear as only a few pixels. Ink pen plotters may tear the paper if they draw complex objects over a small area!

The point is not really whether we clip or not. Some view space plane has to map to z=0 in perspective space and another view space plane has to map to z=1 in perspective space. We've simply declared that these by the near z=zn and far z=zfplanes.


  
Figure 1: A View Volume.
\begin{figure}\centering
\setlength{\unitlength}{0.01in} %
\begin{picture}
(620,...
...515){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{ N}}}
\end{picture}
\end{figure}

Consider the slice of this frustum in the xz plane We find that

\begin{displaymath}\tan(\alpha) = \frac{x_n}{z_n} = \frac{x_f}{z_f}\end{displaymath}


\begin{displaymath}\cot(\alpha) = \frac{z_n}{x_n} = \frac{z_f}{x_f}\end{displaymath}

The (un-normalize) homogeneous points

\begin{displaymath}(x_n\cos(\alpha),\, *,\, *,\, z_n\sin(\alpha)\end{displaymath}


\begin{displaymath}(x_f\cos(\alpha),\, *,\, *,\, z_f\sin(\alpha)\end{displaymath}

both normalize to

\begin{displaymath}(1,\, *,\, *,\, 1)\end{displaymath}

The points $(-x_n,\,z_n)$ and $(-x_f,\,z_f)$ map to $(-1,\, *,\, *,\, 1)$


\begin{picture}(144,90)
\put(72,0){\vector(0,1){100}}
\put(60,90){$z$ }
\put(72,...
...,0){72}}
\put(125,30){$(x_n,\,z_n)$ }
\put(148,70){$(x_f,\,z_f)$ }
\end{picture}

The same mapping works for the y coordinate This yields the matrix transformation

\begin{displaymath}\left[\begin{array}{cccc}
\cos(\alpha) & 0 & * & 0 \\
0 & ...
... 0 & 0 & * & \sin(\alpha) \\
0 & 0 & * & 0 \end{array}\right]\end{displaymath}

We want zn to map to 0 This can be accomplished by the column

\begin{displaymath}\left[\begin{array}{c}
0 \\
0 \\
Q \\
-Qz_n \end{array}\right]\end{displaymath}

for any constant QWe want zf to map to 1. The (un-normalized) homogeneous point

\begin{displaymath}(*,\, *,\, (z_f - z_n)Q,\, z_f\sin(\alpha)\end{displaymath}

should normalize to

\begin{displaymath}(*,\, *,\, 1,\, 1)\end{displaymath}

Thus

\begin{displaymath}Q = \frac{z_f\sin(\alpha)}{z_f - z_n}\end{displaymath}

The perspective view onto $-1\leq x \leq 1$, $-1\leq y \leq 1$, $0\leq z \leq 1$ is given by the matrix

\begin{displaymath}\left[\begin{array}{cccc}
\cos(\alpha) & 0 & 0 & 0 \\
0 & ...
... 0 & Q & \sin(\alpha) \\
0 & 0 & -Qz_n & 0 \end{array}\right]\end{displaymath}

Conclusions

We've looked at perspective projections from their fundamentals. That is, one projects by passing lines from an object to a center of projection through a projection plane. Since each line has a unique direction, the projection in non-linear and can not be represented only using matrices. However, if we introduce homogeneous coordinates and a homogeneous divide we can use a matrix to represent a perspective projection.

We also looked at the usual case where we are projecting onto a plane parallel to the z=0 plane in view space and where the center of projection is on the z axis. The perspective transform in particularly simple in this case.

Finally, we've seen that a good way to implement the perspective transform is to specify, in view space, a field of view angle $\alpha$ and near and far planes z=zn and z=zf that map to z=0 and z=1 in perspective space (after the homogeneous divide).



William Shoaff
2000-09-13