Skip to main content
Logo image

Coordinated Linear Algebra

Section 6.5 Extra Topic: Application to Computer Graphics

Computer graphics deals with images displayed on a computer screen, and so arises in a variety of applications, ranging from word processors, to Star Wars animations, to video games, to wire-frame images of an airplane. These images consist of a number of points on the screen, together with instructions on how to fill in areas bounded by lines and curves. Often curves are approximated by a set of short straight-line segments, so that the curve is specified by a series of points on the screen at the end of these segments.
Matrix transformations are important here because matrix images of straight line segments are again line segments. Note that a color image requires that three images are sent, one to each of the red, green, and blue phosphorus dots on the screen, in varying intensities.
Consider displaying the letter \(A\text{.}\) In reality, it is depicted on the screen, as in the figure below, by specifying the coordinates of the 11 corners and filling in the interior.
For simplicity, we will disregard the thickness of the letter, so we require only five coordinates as in the figure below.
This simplified letter can then be stored as a data matrix
\begin{equation*} D =\begin{bmatrix} 0 \amp 6 \amp 5 \amp 1 \amp 3\\ 0 \amp 0 \amp 3 \amp 3 \amp 9 \end{bmatrix}, \end{equation*}
where the columns are the coordinates of the vertices. Then if we want to transform the letter by a \(2 \times 2\) matrix \(A\text{,}\) we left-multiply this data matrix by \(A\) (the effect is to multiply each column by \(A\) and so transform each vertex).
For example, we can slant the letter to the right by multiplying by a horizontal shear matrix
\begin{equation*} A = \left[ \begin{array}{ll} 1 \amp 0.2\\ 0 \amp 1\\ \end{array} \right]. \end{equation*}
See Formula 6.4.2. The result is the letter with data matrix
\begin{equation*} A = \left[ \begin{array}{ll} 1 \amp 0.2\\ 0 \amp 1 \end{array} \right] \left[ \begin{array}{rrrrr} 0 \amp 6 \amp 5 \amp 1 \amp 3\\ 0 \amp 0 \amp 3 \amp 3 \amp 9 \end{array} \right] = \left[ \begin{array}{lllll} 0 \amp 6 \amp 5.6 \amp 1.6 \amp 4.8\\ 0 \amp 0 \amp 3 \amp 3 \amp 9 \end{array} \right], \end{equation*}
which is shown in the figure below.
If we want to make this slanted matrix narrower, we can now apply a scaling matrix
\begin{equation*} B = \left[ \begin{array}{ll} 0.8 \amp 0\\ 0 \amp 1 \end{array} \right] \end{equation*}
that shrinks the \(x\)-coordinate by \(0.8\text{.}\) See also Formula 6.4.1. The result is the composite transformation
\begin{align*} BAD \amp = \left[ \begin{array}{ll} 0.8 \amp 0\\ 0 \amp 1 \end{array} \right] \left[ \begin{array}{ll} 1 \amp 0.2\\ 0 \amp 1 \end{array} \right] \left[ \begin{array}{rrrrr} 0 \amp 6 \amp 5 \amp 1 \amp 3\\ 0 \amp 0 \amp 3 \amp 3 \amp 9 \end{array} \right] \\ \amp = \left[ \begin{array}{lllll} 0 \amp 4.8 \amp 4.48 \amp 1.28 \amp 3.84\\ 0 \amp 0 \amp 3 \amp 3 \amp 9 \end{array} \right], \end{align*}
which is drawn in the figure below.
On the other hand, we can rotate the letter about the origin through \(\frac{\pi}{6}\) (or \(30^\circ\)) by multiplying by the rotation matrix
\begin{equation*} R_{\frac{\pi}{2}} = \left[ \def\arraystretch{1.5}\begin{array}{rr} \cos(\frac{\pi}{6}) \amp -\sin(\frac{\pi}{6})\\ \sin(\frac{\pi}{6}) \amp \cos(\frac{\pi}{6}) \end{array} \right] = \left[ \begin{array}{ll} 0.866 \amp -0.5\\ 0.5 \amp 0.866 \end{array} \right] \end{equation*}
See Formula 6.4.5 for details. This gives
\begin{align*} R_{\frac{\pi}{2}} \amp = \left[ \begin{array}{ll} 0.866 \amp -0.5\\ 0.5 \amp 0.866 \end{array} \right] \left[ \begin{array}{rrrrr} 0 \amp 6 \amp 5 \amp 1 \amp 3\\ 0 \amp 0 \amp 3 \amp 3 \amp 9 \end{array} \right] \\ \amp = \left[ \begin{array}{lllrr} 0 \amp 5.196 \amp 2.83 \amp -0.634 \amp -1.902\\ 0 \amp 3 \amp 5.098 \amp 3.098 \amp 9.294 \end{array} \right] \end{align*}
and is plotted in the figure below.
This poses a problem: How do we rotate about a point other than the origin? It turns out that we can do this when we have solved another more basic problem.
It is clearly important to be able to translate a screen image by a fixed vector \(\mathbf{w}\text{,}\) that is apply the transformation \(T_{w} : \R^2 \to \R^2\) given by \(T_{w}(\mathbf{v}) = \mathbf{v} + \mathbf{w}\) for all \(\mathbf{v}\) in \(\R^2\text{.}\) The problem is that these translations are not matrix transformations \(\R^2 \to \R^2\) because they do not carry \(\mathbf{0}\) to \(\mathbf{0}\) (unless \(\mathbf{w} = \mathbf{0}\)) (see for instance Exercise 6.4.6.4). However, there is a clever way around this.
The idea is to represent a point
\begin{equation*} \mathbf{v} = \left[ \begin{array}{r} x\\ y \end{array} \right] \end{equation*}
as a \(3 \times 1\) column
\begin{equation*} \left[ \begin{array}{r} x\\ y\\ 1 \end{array} \right], \end{equation*}
called the homogeneous coordinatesof \(\mathbf{v}\text{.}\) Then translation by
\begin{equation*} \mathbf{w} = \left[ \begin{array}{r} p\\ q \end{array} \right] \end{equation*}
can be achieved by multiplying by a \(3 \times 3\) matrix:
\begin{equation*} \left[ \begin{array}{rrr} 1 \amp 0 \amp p\\ 0 \amp 1 \amp q\\ 0 \amp 0 \amp 1 \end{array} \right] \left[ \begin{array}{r} x\\ y\\ 1 \end{array} \right] = \left[ \begin{array}{c} x + p\\ y + q\\ 1 \end{array} \right] = \left[ \begin{array}{c} T_{\mathbf{w}}(\mathbf{v})\\ 1 \end{array} \right]. \end{equation*}
Thus, by using homogeneous coordinates we can implement the translation \(T_{w}\) in the top two coordinates. At the same time, matrix transformations we performed earlier can still be accomplished using homogeneous coordinates. For instance, the matrix transformation induced by
\begin{equation*} A = \left[ \begin{array}{rr} a \amp b\\ c \amp d \end{array} \right] \end{equation*}
is given by a \(3 \times 3\) matrix:
\begin{equation*} \left[ \begin{array}{rrr} a \amp b \amp 0\\ c \amp d \amp 0\\ 0 \amp 0 \amp 1 \end{array} \right] \left[ \begin{array}{r} x\\ y\\ 1 \end{array} \right] = \left[ \begin{array}{c} ax + by\\ cx + dy\\ 1 \end{array} \right] = \left[ \begin{array}{c} A\mathbf{v}\\ 1 \end{array} \right]. \end{equation*}
So everything can be accomplished at the expense of using \(3 \times 3\) matrices and homogeneous coordinates.
It is interesting to examine the geometric implications of homogeneous coordinates. All points of the form \([x,y]\text{,}\) originally located in the \(xy\)-plane in \(\R^2\text{,}\) now have the form \([x,y,1]\) and are located in a horizontal plane \(z=1\) in \(\R^3\text{.}\) What we perceive as a translation in the horizontal plane \(z=1\text{,}\) is actually a shear in \(\R^3\text{.}\) This is similar to how horizontal shears in \(\R^2\) affect points along the line \(y=1\text{:}\) all such points move a fixed distance to the left or to the right.

Example 6.5.1.

Rotate the letter \(A\) through \(\frac{\pi}{6}\) about the point \([4,5]\text{.}\)
Answer.
Using homogenous coordinates for the vertices of the letter results in a data matrix with three rows:
\begin{equation*} K_{d} = \left[ \begin{array}{rrrrr} 0 \amp 6 \amp 5 \amp 1 \amp 3\\ 0 \amp 0 \amp 3 \amp 3 \amp 9 \\ 1 \amp 1 \amp 1 \amp 1 \amp 1 \end{array} \right]. \end{equation*}
If we write \(\mathbf{w} = [4,5]\text{,}\) the idea is to use a composite of transformations: First translate the letter by \(-\mathbf{w}\) so that the point \(\mathbf{w}\) moves to the origin, then rotate this translated letter, and then translate it by \(\mathbf{w}\) back to its original position. The following GeoGebra interactive illustrates this sequence.
Figure 6.5.2.
The matrix arithmetic is as follows (remember the order of composition!):
\begin{align*} \amp \left[ \begin{array}{rrr} 1 \amp 0 \amp 4\\ 0 \amp 1 \amp 5\\ 0 \amp 0 \amp 1 \end{array} \right] \left[ \begin{array}{lrr} 0.866 \amp -0.5 \amp 0\\ 0.5 \amp 0.866 \amp 0\\ 0 \amp 0 \amp 1 \end{array} \right] \left[ \begin{array}{rrr} 1 \amp 0 \amp -4\\ 0 \amp 1 \amp -5\\ 0 \amp 0 \amp 1 \end{array} \right] \left[ \begin{array}{rrrrr} 0 \amp 6 \amp 5 \amp 1 \amp 3\\ 0 \amp 0 \amp 3 \amp 3 \amp 9 \\ 1 \amp 1 \amp 1 \amp 1 \amp 1 \end{array} \right] \\ \amp = \left[ \begin{array}{lllll} 3.036 \amp 8.232 \amp 5.866 \amp 2.402 \amp 1.134\\ -1.33 \amp 1.67 \amp 3.768 \amp 1.768 \amp 7.964 \\ 1 \amp 1 \amp 1 \amp 1 \amp 1 \end{array} \right]. \end{align*}
This discussion merely touches the surface of computer graphics, and the reader is referred to specialized books on the subject. Realistic graphic rendering requires an enormous number of matrix calculations. In fact, matrix multiplication algorithms are now embedded in microchip circuits, and can perform over 100 million matrix multiplications per second. This is particularly important in the field of three-dimensional graphics where the homogeneous coordinates have four components and \(4 \times 4\) matrices are required.

Exercises Exercises

1.

Consider the letter \(A\) below.
Find the data matrix for the letter obtained by:
  1. Rotating the letter through \(\frac{\pi}{4}\) about the origin.
  2. Rotating the letter through \(\frac{\pi}{4}\) about the point \([1,2]\text{.}\)
Answer.
\begin{equation*} {\frac{1}{2}\left[ \begin{array}{ccccc} \sqrt{2} + 2 \amp 7\sqrt{2} + 2 \amp 3\sqrt{2} + 2 \amp -\sqrt{2} + 2 \amp -5\sqrt{2} + 2\\ -3\sqrt{2} + 4 \amp 3\sqrt{2} + 4 \amp 5\sqrt{2} + 4 \amp \sqrt{2} + 4 \amp 9\sqrt{2} + 4 \\ 2 \amp 2 \amp 2 \amp 2 \amp 2 \end{array} \right]}. \end{equation*}

2.

Find the \(3 \times 3\) matrix for reflecting in the line \(y = mx + b\text{.}\) Use \([1,m]\) as direction vector for the line.

3.

Find the \(3 \times 3\) matrix for rotating through the angle \(\theta\) about the point \(P(a, b)\text{.}\)

4.

Find the reflection of the point \(P\) in the line \(y = 1 + 2x\) in \(\R^2\) if:
  1. \(\displaystyle P = P(1, 1)\)
  2. \(\displaystyle P = P(1, 4)\)
  3. What about \(P = P(1, 3)\text{?}\) Explain.
Hint.
Answer.
\(P(\frac{9}{5}, \frac{18}{5})\text{.}\)