next up previous
Next: dd_proj32 Up: dd_proj32 Previous: dd_proj32

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)$.

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 linear map. Thus, the map 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

First consider the case where the viewpoint is the origin and the viewplane is the plane $ z = 1$. The object should be entirely above the $ z = 0$ level, so its points have $ z > 0$. For each point $ (x,y,z)$ in the object, we need to scale it to make the third coordinate equal to $ 1$. The result is $ (x,y,z) \mapsto
(\frac xz, \frac yz, 1)$. In terms of the viewplane coordinates $ (x,y)$, this is

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

If instead the viewpoint is $ (0,0,H)$ for some $ H$, we scale up by a factor of $ H$ instead and get

(3.3 ) \fbox{\((x,y,z) \mapsto \left ({\frac{\displaystyle Hx}{\displaystyle z}},
{\frac{\displaystyle Hy}{\displaystyle z}} \right )\).}

Now consider the case where the setup is the other way around: The viewplane is $ z = 0$ and the viewpoint is $ (0,0,H)$. In the earlier formula, we simply replace $ z$ by $ H - z$ to switch 0 and $ H$ as $ z$-values, and we get $ (x,y,z) \mapsto \left (\frac {Hx}{H - z}, \frac {Hy}{H - z} \right )$, or equivalently,

(3.4 ) \fbox{\((x,y,z) \mapsto \left ({\frac{\displaystyle x}{\displaystyle 1 - \frac zH}},
{\frac{\displaystyle y}{\displaystyle 1 - \frac zH}}\right )\).}

This is logical: $ x$ and $ y$ have been scaled by an amount that depends on $ z$.

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$. For the vertices $ (\pm 1, \pm 1, +1)$ on the top face we get
$ (\pm 1, \pm 1, 1) \mapsto (\pm \frac 43, \pm \frac 43)$.

Similarly, for the vertices on the bottom face we get

$ (\pm 1, \pm 1, -1) \mapsto
(\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: dd_proj32 Up: dd_proj32 Previous: dd_proj32
Kirby A. Baker 2003-05-28