next up previous
Next: o_projs32 Up: o_projs32 Previous: o_projs32

3. How to calculate projections

The object is given as points in R$ ^ 3$. For an object described by line segments and polygons, all you need is the vertices; the images of the vertices can be connected up with line segments just as the vertices were. (Again, this ignores the question of hidden lines.)

The image is in the $ x,y$-plane, which really consists of points $ (x,y,0)$ in R$ ^ 3$, but we'd like images as points in R$ ^ 2$ so that they are ready to plot on paper or on a screen.



(I) Orthographic

Easy: $ (x,y,z) \mapsto (x,y)$.



(II) Oblique

Here the rays are parallel and slanted. To describe the direction of the rays, we use a vector V. It turns out to be easiest if V is multiplied by a scalar to make the third coordinate 1; this will still describe the same rays Thus, we write V$ = (a,b,1)$. (The viewpoint is at infinity with homogeneous coordinates $ (a,b,1,0) _ h$.)

A good method is to apply a viewing transformation to make the rays perpendicular to the viewplane while leaving the viewplane alone. After applying this transformation to the object, we are back in Case (I). See Figure [*].

Since the origin stays fixed and parallel lines stay parallel, the transformation is a homogeneous linear transformation. Thus, the transformation will be given by a $ 3 \times 3$ matrix $ A$ taking $ (1,0,0) \mapsto (1,0,0)$, $ (0,1,0) \mapsto (0,1,0)$ (since these are both in the viewplane, which stays fixed), and $ (a,b,1) \mapsto (0,0,1)$ (to make V perpendicular to the $ x,y$-plane).

Notice that it would be easier if the transformation did the opposite, since then we'd have images of standard basis vectors. So, let $ B$ be a $ 3 \times 3$ matrix taking

$ (1,0,0) \mapsto (1,0,0)$
$ (0,1,0) \mapsto (0,1,0)$
$ (0,0,1) \mapsto (a,b,1)$

Therefore $ B = \left[\begin{array}{ccc}1&0&0\\  0&1&0\\  a&b&1\end{array}\right]$. Since $ B$ is the inverse of $ A$, we have $ A = \left[\begin{array}{rrr}1&0&0\\  0&1&0\\  -a&-b&1\end{array}\right]$.
(Here we can use the special method of taking inverses of matrices that are like $ I$ except in the off-diagonal entries of one row or one column.)

Now, to find the image of a point, just multiply by $ A$ and then project orthographically:

$ (x,y,z) \mapsto (x,y,z)\left[\begin{array}{rrr}1&0&0\\  0&1&0\\  -a&-b&1\end{array}\right] =
(x-az,y-bz,z) \mapsto (x-az,y-bz)$, or briefly,

3.1 \fbox{\((x,y,z) \mapsto (x-az,y-bz)\)}.

In practice, you can either apply this method with the matrix multiplication or else program the final formula $ (x,y,z) \mapsto (x-az,y-bz)$. You can think of this formula as saying that the image of $ (x,y,z)$ consists of $ (x,y)$ but offset linearly somewhat, depending on $ z$. See Figure [*].

Figure: Viewing transformation of oblique projection
.9book/05dir/fig3.eps

Example: (a) Find the viewing transformation for an oblique projection from the direction $ (2,3,5)$. (b) Under this projection, find the image of the $ 2 \times 2 \times 2$ cube with vertices $ (\pm 1, \pm 1 \pm 1)$.

Solution: (a) Scaling $ (2,3,5)$ we get V$ = (0.4,0.6,1)$, so the viewing matrix is
$ \left[\begin{array}{ccc}1&0&0\\  0&1&0\\  -0.4&-0.6&1\end{array}\right]$.

(b) The top face, with points $ (\pm 1, \pm 1, +1)$, goes to points $ (\pm 1 - 0.4, \pm 1 -0.6)$. The bottom face, with points $ (\pm 1, \pm 1, -1)$ goes to points $ (\pm 1 + 0.4, \pm 1 + 0.6)$. In R$ ^ 2$, these are $ 2 \times 2$ squares offset from one another. Connect them up and you have the traditional oblique picture of a cube, as shown in Figure [*].



(Notice that in this example the cube straddles the viewplane, but this has no effect on the formulas. Rather, there is one formula, and it works no matter whether $ z$ is positive or negative.)

Figure: Oblique image of cube in plane
.4book/05dir/obl.ps

(III) Perspective

Let's consider just the case where the viewpoint is on the $ z$-axis, so it has the form $ (0,0,H)$ for some height $ H$. The object should lie entirely below this height.

Following the idea used for oblique projections, let's try to find a ``viewing transformation'' that changes the picture to an orthographic projection. This time the viewpoint is an ordinary point and needs to be changed to a point at infinity, so we need to use a projective transformation.

Discussion. Recall that the key points for handling projective transformations are
$ X = pt(1,0,0,0) _ h$, at infinity on the $ x$-axis,
$ Y = pt(0,1,0,0) _ h$, at infinity on the $ y$-axis,
$ Z = pt(0,0,1,0) _ h$, at infinity on the $ z$-axis,
$ O = pt(0,0,0,1) _ h$, the origin.
(There was also $ E$, but we won't need it.)

The given viewpoint is $ (0,0,H) = pt(0,0,H,1) _ h$, but it turns out to be best to use the equivalent homogeneous coordinates $ pt(0,0,1,1/H) _ h$. The new viewpoint, at infinity on the $ z$-axis, is to be $ Z$. Since $ X,Y,O$ are in the $ x.y$-plane, they should stay fixed. Then we want to find a $ 4 \times 4$ matrix $ A$ that gives a projective transformation taking

$ X \mapsto X$, $ Y \mapsto Y$, $ pt(0,0,1,1/H) _ h \mapsto Z$, $ O \mapsto O$.

Notice that it is easy to find a $ 4 \times 4$ matrix $ B$ to go in the opposite direction, since the coordinates of $ X,Y,Z,O$ are standard basis vectors in R$ ^ 4$: Just let the rows of $ B$ be the images of these standard basis vectors, so that

$ B = \left[\begin{array}{cccc}1&0&0&0\\  0&1&0&0\\  0&0&1&\frac 1H\\  0&0&0&1\end{array}\right]$. Then

$ A = B ^{-1} = \left[\begin{array}{cccc}1&0&0&0\\  0&1&0&0\\  0&0&1&-\frac 1H\\  0&0&0&1\end{array}\right]$,

again since $ B$ is like $ I$ except for the off-diagonal entries in one row. $ A$ gives the viewing transformation.

Now, under the viewing transformation, $ (x,y,z) = pt (x,y,z,1)
\mapsto pt (x,y,z,1)A = pt (x,y,z,1-z/H) _ h$. To find the equivalent ordinary point, divide through by the last homogeneous coordinate, to get $ pt(x/(1-z/H),y/(1-z/H),z/(1-z/H),1) _ h =
(x/(1-z/H),y/(1-z/H),z/(1-z/H))$. Finally, we need to project orthographically by discarding the third coordinate. This gives the final result that

3.2 \fbox{\(\displaystyle (x,y,z) \mapsto \left (\frac x{1-z/H},\frac y{1-z/H} \right )\)}.

As before, you can either apply this method as a formula, or actually transform points with a viewing transformation and then project. Since we assumed that the object lies below the height $ H$ of the viewpoint, the denominator $ (1-z/H)$ is always positive. See Figure [*].

Figure: Viewing transformation of perspective projection
.9book/05dir/fig4.eps

Example. Suppose we want a perspective picture of the cube $ (\pm 1, \pm 1, \pm 1)$ on the $ x,y$-plane from the viewpoint $ (0,0,4)$. This is the case $ H = 4$. Using the perspective transformation, for the vertices $ (\pm 1, \pm 1, +1)$ on the top face we get
$ (\pm 1, \pm 1, 1) = pt~(\pm 1, \pm 1, 1, 1) _ h \mapsto
pt~(\pm 1 \pm 1, 1,1)\...
...{array}{rrrr}1&0&0&0\\  0&1&0&0\\  0&0&1&-\frac 14\\  0&0&0&1\end{array}\right]$

$ = pt (\pm 1, \pm 1,1,\frac 34) _ h = pt(\pm \frac 43, \pm \frac 43, \frac 43,1)
_ h = (\pm \frac 43, \pm \frac 43, \frac 43)$, which projects orthographically to $ (\pm \frac 43, \pm \frac 43)$.

Similarly, for the vertices on the bottom face we get

$ (\pm 1, \pm 1, -1) = pt~(\pm 1, \pm 1, -1, 1) _ h \mapsto
pt~(\pm 1 \pm 1, -1,...
...{array}{rrrr}1&0&0&0\\  0&1&0&0\\  0&0&1&-\frac 14\\  0&0&0&1\end{array}\right]$

$ = pt (\pm 1, \pm 1,-1,\frac 54) _ h = pt(\pm \frac 45, \pm \frac 45,- \frac 45,1)
_ h = (\pm \frac 45, \pm \frac 45, -\frac 45)$, which projects orthographically to $ (\pm \frac 45, \pm \frac 45)$. Joining up these eight points, you get the ``square inside a square'' perspective image of the cube. See Figure [*].

Figure: Perspective image of cube in plane
.4book/05dir/persp.ps




next up previous
Next: o_projs32 Up: o_projs32 Previous: o_projs32
Kirby A. Baker 2002-01-28