Some computers can only draw straight lines on the screen, but complicated drawings can be made with a long series of line-drawing instructions. For example, the letter ``F'' could be drawn in its normal orientation at the origin with the following set of instructions:
Imagine that you have a drawing that's far more complicated than the ``F'' above consisting of thousands of instructions similar to those above. Let's take a look at the following sorts of problems:
It turns out that the answers to all of the problems above can be achieved by multiplying your vectors by a matrix. Of course a different matrix will solve each one. Here are the solutions:
Graphics Solution 1:
To scale in the
-direction by a factor of 2, we need to multiply
all the
coordinates by 2. To scale in the
-direction, we
similarly need to multiply the
coordinates by the same scale
factor of 2.
The solution to scale any drawing by a factor
in the
-direction
and
in the
-direction is to multiply all the input vectors
by a general scaling matrix as follows:
To uniformly scale everything to twice as big, let
. To
scale by a factor of 2 in the
-direction and 3 in the
-direction, let
and
.
We'll illustrate the general procedure with the drawing instructions
for the ``F'' that appeared earlier. The drawing commands are
described
in terms of a few points:
,
,
,
, and
.
If we write all five of those points as column vectors and multiply
all five by the same matrix (either of the two above), we'll get five
new sets of coordinates for the points. For example, in the case of
the second example where the scaling is 2 times in
and 3 times
in
, the five points will be converted by matrix multiplication
to:
,
,
,
and
. If we rewrite
the
drawing instructions using these transformed points, we get:
Graphics Solution 2:
A mirror image is just a scaling by
. To mirror through the
-axis means that each
-coordinate will be replaced with its
negative. Here's a matrix multiplication that will do the job:
Graphics Solution 3:
To translate points 4 to the right and 5 units down, you essentially
need to add 4 to every
coordiante and to subtract 5 from every
coordinate. If you try to solve this exactly as in the examples
above,
you'll find it is impossible. To convince yourself it's
impossible with any
matrix, consider what will
happen to the origin:
. You want to move it to
,
but look what happens if you multiply it by any
matrix (
,
,
, and
can be any numbers):
In other words, no matter what
and
are, the matrix
will map the origin back to the origin, so translation using this
scheme is impossible.
But there's a great trick2. For every one of
your two-dimensional vectors, add an artificial third component of 1.
So the point
will become
, the origin will
become
, et cetera. The column vectors will now have three
rows, so the transformation matrix will need to be
. To
translate by
in the
-direction and
in the
-direction, multiply the artifically-enlarged vector by a matrix as
follows:
But now you're probably thinking, ``That's a neat trick, but what happens to the matrices we had for scaling? What a pain to have to convert to the artificial 3-dimensional form and back if we need to mix scaling and translation.'' The nice thing is that we can always use the artifically extended form. Just use a slightly different form of the scaling matrix:
In the solutions that follow, we'll always add a 1 as the artifical third component3.
Graphics Solution 4:
Convince yourself (by drawing a few examples, if necessary) that to
rotate a point counter-clockwise by
about the origin, you
will basically make the original
coordinate into a
coordinate,
and vice-versa. But not quite. Anything that had a positive
coordinate will, after rotation by
, have a negative
coordinate and vice-versa. In other words, the new
coordinate is
the old
coordinate, and the new
coordinate is the negative of
the old
coordinate. Convince yourself that the following matrix
does the trick (and notice that we've added the 1 as an artificial
third component):
The general solution for a rotation counter-clockwise by an angle
is given by the following matrix multiplication:
If you've never seen anything like this before, you might consider
trying it for a couple of simple angles, like
or
and put in the drawing coordinates for the
letter ``F'' given earlier to see that it's transformed properly.
Graphics Solution 5:
Here is where the power of matrices really comes through. Rather than
solve the problem from scratch as we have above, let's just solve it
using the information we already have. Why not translate the
point
to the origin, then do a rotation about the
origin, and finally, translate the result back to
? Each of
those operations can be achieved by a matrix multiplication. Here is
the
final solution:
Notice carefully the order of the matrix multiplication. The matrix
closest to the
column vector is the first one that's applied
to it--it should move
to the origin. To do that, we need to
translate
coordinates by
and
coordinates by
. The
next operation to be done is the rotation by an arbitrary angle
, using the matrix form from the previous problem. Finally,
to translate back to
we have to translate in the opposite
direction from what we did originally, and the matrix on the far
left above does just that.
Remember that for any particular value of
,
and
are just numbers, so if you knew the exact rotation
angle, you could just plug the numbers in to the middle
matrix and multiply together the three matrices on the left. Then to
transform any particular point, there would be only one matrix
multiplication involved.
To convince yourself that we've got the right answer, why not
put in a particular (simple) rotation of
into the
matrices and work it out?
and
, so the product of the three matrices on the left is:
Graphics Solution 6:
The answer is yes. Of course you'll have to add an artificial fourth dimension which is always 1 to your three-dimensional coordinates, but the form of the matrices will be similar.
On the left below is the mechanism for scaling by
,
, and
in the
-,
-, and
-directions; on the right is a
multiplication that translates by
,
, and
in the three
directions.
Finally, to rotate by an angle of
counter-clockwise about
the three axes, multiply your vector on the left by the appropriate
one of the following three matrices (left, middle, and right correspond
to rotation about the
-axis,
-axis, and
-axis: