Vector Math For 3D Computer Graphics
Vector Math For 3D Computer Graphics
This is a tutorial on vector algebra and matrix algebra from the viewpoint of computer
graphics. It covers most vector and matrix topics needed for college-level computer graphics
text books. Most graphics texts cover these subjects in an appendix, but it is often too short.
This tutorial covers the same material at greater length, and with many examples.
Although primarily aimed at computer science students, this tutorial is useful to all
programmers interested in 3D computer graphics or 3D computer game programming. In spite
of their appealing blood-and-gore covers, mass trade books on game programming require the
same understanding of vectors and matrices as more staid text books (and usually defer these
topics to the same skimpy mathematical appendix).
This tutorial is useful for more than computer graphics. Vectors and matrices are used in all
scientific and engineering fields, and any other field that uses computers (are there any that
don't?) In many fields, the vocabulary used for vectors and matrices does not match that used
in computer graphics. But the ideas are the same, and reading these notes will take only a
slight mental adjustment.
These notes assume that you have studied plane geometry and trigonometry sometime in the
past. Notions such as "point", "line", "plane", and "angle" should be familiar to you. Other
notions such as "sine", "cosine", "determinant", "real number", and the common trig identities
should at least be a distant memory.
These pages were designed at 800 by 600 resolution with "web safe" colors. They have been
(somewhat) tested with not-too-old versions of Netscape Navigator and Internet Explorer, using
"Times Roman" font (the usual browser default font). Many pages require Javascript, and some
pages require Java. If you lack these (or are behind a firewall that does not allow these inside)
you will be able to read most pages, but the interactive features will be lost.
Some sections are more than three years old and have been used in several lecture sections
(and hence are "classroom tested" and likely to be technically correct and readable). Other
sections have just been written and might fall short of both goals.
This tutorial may be freely downloaded and used as long as copyright and authorship
information is not removed. (They are contained in HTML comments on each page.) People
who wish to reward this effort may do so by going to their local public library and checking out
any long neglected, lonely book from the stacks.
Chapter Topics:
Computer graphics books use one of two ways to represent points and vectors. Some books use row
matrices; other books use column matrices. The two methods are exactly equivalent (although some
formulae have to be adjusted). These notes use column matrices.
Some graphics books use the term "column vector" for the object that these notes call a "column
matrix." This is just a variation in terminology and does not affect the concepts or formulae presented
here.
QUESTION 1:
(Review: ) What two types of objects are represented with column matrices?
Virtual Tourist
By "geometrical point" these notes will mean the "point" of plane geometry and solid geometry.
Hopefully you have studied geometry sometime in the past.
Computer graphics consists of two activities: (1) Creating an imaginary world inside a computer, and
(2) producing two dimensional images of that world from various viewpoints. A graphics program is
like a tourist wandering through a fantastic landscape taking pictures with a camera. With computer
animation, the virtual tourist is equipped with a movie camera.
The imaginary landscape is built of objects in three dimensional space. Each object is a set of points
and connections between points that form the edges of a 3D solid. Here, for example is a set of points
that model a teapot (from the Open GL Utility Toolkit):
It may be hard to see, but the figure consists of points and the line segments that connect them. To
make a realistic picture of a teapot many operations are needed to fill in the area between line
segments, apply texture and lighting models, and other rendering operations. But the fundamental
QUESTION 2:
A hard question. Again, you should have an idea of what a line is from your study of geometry.
Vector
In geometry, a point is a location in space. A point does not have any size, its only property is
location. In computer graphics, points will mostly be the vertices of 3D figures.
A vector has two properties: length and direction. A vector does not have a fixed location in space.
The idea is that points are used to encode location, and vectors are used to encode connections
between points. This may seem rather odd, but it makes 3D computer graphics easier.
The combination of "distance and direction" is sometimes called a displacement. Often the same
displacement (i.e. just one displacement) is applied to each of several points. For example, consider
this cube:
The front face contains four vertices (four points). If you move the same distance and direction from
each of these points you reach the four vertices of the back face.
The "same distance and direction" is a vector, shown here as a line with an arrow head. The diagram
shows this one vector four times, once for each point of the face.
QUESTION 3:
Yes. The "direction to the Sun" is the same for all locations on the beach. In other words, it is a
vector.
Column Matrix
Sometimes (as in the question) we are interested only in direction. A vector is used for this, but its
length does not matter. Often it will be given a length of one.
A geometric vector may be represented with a list of numbers called a column matrix. A column
matrix is an ordered list of numbers written in a column. Here is an example of a column matrix:
Each number of the column matrix is called an element. The numbers are real numbers. The number
of elements in a vector is called its dimension. A row matrix is an ordered list of numbers written in
a row. Here is an example of a row matrix:
(12.5, -9.34)
To be consistent, our vectors will always be represented with column matrices. Some books represent
vectors with row matrices, which makes no fundamental difference.
QUESTION 4:
Column
Matrix
Dimension . ? . . ? . . ? .
Column
Matrix
Dimension 3 4 4
Variables as Elements
The elements of a column matrix can be variables:
The first element in a column matrix is sometimes given the index "0", and sometimes "1".
QUESTION 5:
No. A column matrix is an ordered list of numbers. This means that each position of the column
matrix contains a particular number (or variable.)
The "T" stands for transpose, which means to change rows into columns (later on a more elaborate
definition of "transpose" will be needed.)
QUESTION 6:
No. Column matrices and row column matrices are different types of objects, and cannot be equal.
Here is what it takes for two row or two column matrices to be equal:
Only matrices of the same "data type" can be compared. You can compare two three-dimensional
column matrices, or two four-dimensional row matrices, and so on. It makes no sense to compare a
three-dimensional row column matrix to a three-dimensional column matrix. For example:
( 6, 8, 12, -3 )T = ( 6, 8, 12, -3 )T
( 6, 8, 12, -3 ) = ( 6, 8, 12, -3 )
( 6, 8, 12, -3 )T =/= ( 6, 8, 12 )T
Sometimes the rules are relaxed and one gets a little sloppy about the distinction between row column
matrices and column matrices. But keeping the distinction clear is like "strong data typing" in
programming languages. It often keeps you out of trouble.
QUESTION 7:
No.
.
.
.
4
3
2 row
1 column
______ dimensional _______ matrix
For example "3 dimensional column matrix", or "4 dimensional row matrix". In a strongly typed
programming language, you might declare a type for each of the matrix types. For example, in C:
...
This gets awfully tedious, so usually you create a more general data type and hope that the user will
keep row matrices and column matrices straight without help from the compiler. An elegant solution
is to use object-oriented programming.
Since for us vectors will always be represented with column matrices, we will use only a few types.
QUESTION 8:
( 2, -1 )T
( 2.0, -1.0 )T
( 2, -1 )T
( 2.0, -1.0 )T
Yes---for us, matrix elements are always real numbers (never integers) so for us "2" is short for "2.0" .
a == ( 1.2, -3.6 )
x == ( x1, x2, x3, x4 )
r == ( r0, r1 )T
It is conventional to use names from the start of the alphabet for column matrices whose elements we
know (like a above), and to use names from the end of the alphabet for column matrices whose
elements are variables.
Often the names of column matrix elements are subscripted versions of the name of the whole column
matrix (like column matrix r and its elements r0 and r1).
Bold face is hard to do with pencil or chalk, so instead an arrow or a bar is placed over the name:
_ ->
x x
QUESTION 9:
x = ( x1, x2 )
y = ( 3.2, -8.6 )
x = y
x = ( x1, x2 )
y = ( 3.2, -8.6 )
x = y
d = (5, 2)T
QUESTION 10:
The column matrix d represents the displacement vector from point A to point B. What column
matrix represents displacement from point B to point A?
e = (-5, -2)T
Displacement
When the points are visited in the opposite order, the
displacement vector points in the opposite direction. In
the column matrix each element is -1 times the old value.
QUESTION 11:
Say that point C is x=4, y=2 and that point D is x=3, y= 5 . What column matrix represents the
displacement from C to D?
Say that point C is x=4, y=2 and that point D is x=3, y= 5 . What column matrix represents the
displacement from C to D?
● Finish X - Start X = 3 - 4 = -1
● Finish Y - Start Y = 5 - 2 = 3
QUESTION 12:
(7, 3)T
Checking an Answer
To check your answer, start at the beginning point and follow the directions: walk 7 in X, then walk 3
in Y. If your answer is correct, you end up at the ending point.
QUESTION 13:
What is the displacement from point G, (-3, 4)T to point H, (5, -2)T ?
What is the displacement from point G, (-3, 4)T to point H, (5, -2)T ?
Subtracting values of the start G from corresponding values of the finish H gives: (8, -6)T
QUESTION 14:
Yes.
Subtracting Points
No, I'm not talking about your midterm
The previous formula for calculating a displacement vector (click here to review it) can be written as:
F - S = ( Xf , Yf )T - ( Xs , Ys )T = ( Xf-Xs , Yf-Ys )T
Don't skip over this observation with a yawn. Think a few careful thoughts now to avoid confusion
later on. It is slightly odd that a "minus" with two objects of one type produces an object of another
type.
QUESTION 15:
(Thought question: ) If one three dimensional point is subtracted from another, is the result a vector?
(Thought question: ) If one three dimensional point is subtracted from another, is the result a vector?
QUESTION 16:
Through what displacement should Amy move to find her friend Emily?
By subtracting points:
Of course by counting squares of the graph paper you will get the same answer.
Real Numbers
With the story problem, there is a temptation to avoid negative numbers and to incorrectly compute
the displacement. But it is perfectly OK to have negative displacements; the "negative" part just
shows the direction:
Another thing to keep in mind is that the elements of a column matrix are real numbers. Examples
often use integers, but that is just to make things easy. There is nothing wrong with the column matrix
( -1.2304, 9.3382 )T.
QUESTION 17:
You have reached the end of this chapter. Before you go vectoring off to the campus nightspot,
perhaps you would like to review some terms:
The next chapter will discuss operations on vectors and the equivalent operations with column
matrices.
This chapter discusses addition and subtraction of column and row matrices.
QUESTION 1:
(Review question.) What is it called when a row matrix is "flipped" into a column matrix (or when a
column matrix is flipped into a row matrix)?
Transposition.
Transposition
Your browser must be Java enabled to see this. Even if a row matrix and a column matrix are
the same dimension and contain the same
elements, they are considered different types. Remember that a "T" superscript is used when a column
matrix is written as a row of numbers. The first element of a column matrix is the topmost
(corresponding to the leftmost element when written as a row.)
The picture to the left shows two different ways of writing out the same column matrix. To change an
element, enter a new value into its box and hit enter. When the column matrix is written in a row (to
save space) the superscript "T" shows that it is really a column matrix. Notice that the elements of the
column matrix have the same subscripts no matter how the column matrix is displayed.
A "T" superscript on column matrix with means to flip the column into a row resulting in a row
matrix.
QUESTION 2:
What is ( 1, 2, 3 )T T
( 1, 2, 3 )T T = ( 1, 2, 3 )
Transposing twice gives you what you started with. This seems a bit dumb right now, but later on when you are doing algebraic
manipulation it might help to remember this.
Addition is done by adding corresponding elements of the input matrices to produce each corresponding element of the output
matrix. Row matrices are added in the same way.
( 9.2, -8.6, 3.21, 48.7 ) + ( -2.1, 4.3, 1.0, 2.3 ) = ( 7.1, -4.3, 4.21, 51.0 )
If a and b are matrices of the same type, then a + b = c means that each element ci = ai + bi
QUESTION 3:
( 2, -2 )T + ( 8, 6 )T =
( 2, -2 )T + ( 8, 6 )T = ( 10, 4 )T
QUESTION 4:
( 8, 4, 6 )T + ( 2, -2, 9 )T =
( 2, -2, 9 )T + ( 8, 4, 6 )T =
( 8, 4, 6 )T + ( 2, -2, 9 )T = ( 10, 2, 15 )T
( 2, -2, 9 )T + ( 8, 4, 6 )T = ( 10, 2, 15 )T
Commutative
You might suspect that the last problem is supposed to sneak in another math fact. You are right:
Matrix addition is commutative. This means that
a + b = b + a.
This works for both row and column matrices of all dimensions. It is also true that:
a + b + c = b + c + a = c + a + b = .....
In other words, the order in which you add matrices does not matter. At least for addition, matrices
work the same way as numbers, since, of course, 1 + 2 = 2 + 1. We will not always be so fortunate as
to have matrices and numbers work the same way.
QUESTION 5:
( -1, -2, 3 )T + ( 1, 2, -3 )T =
( -1, -2, 3 )T + ( 1, 2, -3 )T = ( 0, 0, 0 )T
A matrix with all zero elements is sometimes called a zero matrix. The sum of a zero matrix and a
matrix a of the same type is just a.
In symbols the zero matrix is written as 0 (bold face zero) which is different than 0, the real number
zero. Whether 0 is a row or column, and the number of elements in 0 depends on context.
QUESTION 6:
Some students spoil my fun by realizing that (since matrix addition is commutative) the matrices can be rearranged into a
more favorable order. Once the matrices are in a nice order, you can pick whichever "+" you want to do first. That last idea
has a name:
This says "first add a to b then add that result to c." The result will be the same as if you did "add a to the result of adding b
with c." This works for both row and column matrices of all dimensions.
QUESTION 7:
Thirty seconds to go on your midterm and you discover that you have left out a problem:
\ /
\ /
\ /
\ /
\ /
( 25.1, -19.6 ) + ( 12.4, 8.92 ) + ( -25.1, 19.6 ) = ( 12.4, 8.92 )
( 84.02, 90.31 ) + ( -14.23, 10.85 )T <---- can't add two a row matrix
to a column matrix
( 84.02, 90.31 ) + ( -14.23, 10.85, 32.75 ) <---- can't add matrices of different
dimensions
These problems are clear when the elements are written out, as above, but it is less clear when variable symbols are used:
There are some strange-looking things you can do, such as in the following:
QUESTION 8:
Matrix Subtraction
Two matrices of the same type can be subtracted to produce a third matrix of the same type. As you probably imagine,
subtracting two matrices means subtracting the corresponding elements, being careful to keep the elements in the same
order:
If a and b are matrices of the same type, a - b = c means that each element ci = ai - bi
QUESTION 9:
(22, 5, -12 ) - (10, -5, 3 ) = ( 22 - 10, 5 - (-5), -12 - 3 ) = ( 12, 10, -15 )
Not Commutative
Another Math Fact emerges:
Matrix subtraction is NOT commutative. This means that you can't change the order when doing a - b.
In symbols: if a is ( a0, a1, ..., a2) then -a means ( -a0, -a1, ..., -a2).
QUESTION 10:
The "outside -" was used to negate the second matrix, then the resulting two matrices were added. In
symbols:
a - b = a + (-b)
This can be more useful to remember than it at first appears. You can negate matrices so the problem is
one of matrix addition, then rearrange the addition (because addition is commutative):
a - b + c - d = a + (-b) + c + (-d)
= (-d) + a + c + (-b)
= any rearrangement you want
a + (-a) = 0
a - a = 0
Notice that the 0 means the zero matrix, the matrix of the same type as a, but with all elements zero.
QUESTION 11:
This looks like another trap. Rather than blindly rushing in and calculate, try rearranging things:
You would probably skip a few steps if you were doing this mentally.
More Practice
Do a few more practice problems before you move on.
QUESTION 12:
a + b + c = 0
a + b + c = 0
So it must be that:
12.8+x = 0
9.6+y = 0
0.9+z = 0
Oh No! Algebra
Yes, algebra. The problem was: find the elements of c when
a + b + c = 0
If you didn't know they were matrices, you might have been tempted to work this using real number algebra:
a + b + c = 0
a + b = -c + 0
(a + b) = -c
-(a + b) = c
In fact, this works. As long as every matrix is of the same type, and the operations are only "+" or "-", you can pretend that you are doing
ordinary algebra. Notice that the last equations means "add a with b, negate the result, then the result is equal to c."
If this is too ugly for you this early in the morning, mentally erase some of the junk:
a0 + b0 + c0 = 0
a0 + b0 = -c0 + 0
a0 + b0 = -c0
a0 + b0 = -c0
-( a0 + b0) = c0
Of course the other elements follow the same pattern so the result is true for the matrix as a whole.
QUESTION 14:
a = ( -4, 2 )T
b = ( 8, 3 )T
c = ( c0, c1 )T
a + b + c = 0
a = ( -4, 2 )T
b = ( 8, 3 )T
c = ( c0, c1 )T
a + b + c = 0
a + b + c = 0
a + b = -c
( 4, 5 )T = -( c0, c1 )T
-( 4, 5 )T = ( c0, c1 )T
( -4, -5 )T = ( c0, c1 )T
c0 = -4
c1 = -5
Click on a term to see where it was discussed in this chapter. Remember to click on the "Back" arrow
of your browser to get back to this page. The next chapter will suggest ways in which what you have
learned may be useful.
QUESTION 1:
a = ( 3, 2 )T
b = ( -2, 1 )T
a = ( 3, 2 )T
b = ( -2, 1 )T
a + b = c = ( 1, 3 )T
Vectors in 2D Space
Vectors are geometric objects. A particular vector can be represented in a variety of ways. It is
important to understand the difference between a geometric object (such as a point or a vector) and
the way it is represented (often with a column matrix).
Recall that in computer graphics it is common for a virtual world to be modeled with points a vectors.
As the virtual tourist (or the "hero" of a first-person computer game) wanders through the world it
does not change (much), but the viewpoint and resulting 2D image changes greatly. The geometric
points and vectors do not change, but as the viewpoint changes, their representations as column
matrices changes constantly.
u+v=w
QUESTION 2:
Position Independent
The diagram included points to make it clear how vector addition is used.
But more commonly vector addition is shown as in the diagram at left. The
diagram shows that the effect of moving through the displacement u and
then moving through the displacement v is the same as moving through the
displacement w, no matter where you start from.
For example, say that you wish to move all the points of a geometric object through displacement u
and then through displacement v. You could do this by moving each point through displacement w
(ie. w does not depend on position).
QUESTION 3:
Mentally draw the line in the diagram that represents the sum of
vector s with vector t.
Head-to-Tail Rule
The rule for adding vector u to vector v is:
QUESTION 4:
The diagram shows sliding the vector e until its tail touches the head of
d. The result is the vector from the tail of d to the head of e.
Vector Addition in 3D
The diagram shows 3D vectors a and b
added to form c (the 3D figure is there to
aid in visualizing the three dimensions).
The head-to-tail rule works in 3D as
well.
QUESTION 5:
Is it possible (do you think) to add three vectors together, like a+b+d in the figure?
Yes. The result is the total displacement that would result in following each vector in turn.
Associative
The top diagram shows the result of
adding (a+b) + d = c + d. The result is
the vector with length and direction the
same as the diagonal of the figure.
a + (b + c) = (a + b) + c
The associative property means that sums of several vectors can be written like a + b + c + d + e
without parentheses.
QUESTION 6:
Say that you walk five blocks north, and then three blocks east. Will you end up at the same place if
you walk three blocks east and then five blocks north?
Say that you walk five blocks north, and then three blocks east. Will you end up at the same place if
you walk three blocks east and then five blocks north?
Yes.
Commutative
Vector addition is commutative, just like
addition of real numbers. That is:
Notice how in the diagram the head-to-tail rule yields vector c for both a+b and b+a.
QUESTION 7:
Yes.
For now, let us talk about 2D space. The left diagram shows a (rather simple) virtual world in 2D space.
The points and vectors exist in the space independent of any coordinate frame. The next diagram shows
the same virtual world, this time with a coordinate frame consisting of a particular point P0 and two axes.
In this coordinate frame, the point A is represented by the column matrix (2, 2)T.
The right diagram shows the same virtual world, but with a different coordinate frame. In the second
coordinate frame, the point A is represented by the column matrix (2, 3)T.
QUESTION 8:
Or, you could pick some other frame and say "17 inches from the left edge of the table and 38 inches
from the back edge." Or you could describe where it is in relation to the foot of the left front leg of the
table, or....
QUESTION 9:
As you are out for a walk, a stranger approaches you and asks for directions to the post office. Which
coordinate frame will you use: latitute and longitude, or number of city blocks left and right of your
current position?
Unless the stranger has a GPS receiver, the city block coordinate frame is likely to be the most useful.
Back to our exciting virtual world. The displacement from point A to point B is the vector v. The vector
does not depend on any coordinate system. Using the first coordinate system (middle diagram) the
displacement is represented as
In the diagram this is (4, 0)T. Moving 4 units from point A in the direction of the x axis brings us to point
B. In the second coordinate system (right diagram) the same vector is represented by (2.8, -1.4)T.
QUESTION 10:
Points and vectors both are represented with column matrices. Is this likely to be confusing?
Yes. In your graphics text this confusion leads to the use of homogeneous coordinates, a different way
of representing points and vectors with column matrices.
If vectors are represented with column matrices, then vector addition is represented by addition of
column matrices. For example:
a = ( 3, 2 )T
b = ( -2, 1 )T
a + b = c = ( 1, 3 )T
The diagram shows the head-to-tail rule used to add a and b to get c. Adding the column matrices a
and b yields the column matrix c. This matrix is the correct representation of the vector c.
QUESTION 11:
b + a = c = ( 1, 3 )T
1. Draw the first vector b as an arrow with its tail at the origin.
2. Draw the second vector a as an arrow with its tail at the point of the first.
3. The sum is the arrow from the origin to the tip of the second vector.
(Remember that vectors have no location so you can draw a picture of a vector with its tail starting on
any point you want.)
QUESTION 12:
(Review: ) Are vector addition and column matrix addition both associative?
(Review: ) Are vector addition and column matrix addition both associative?
Yes.
Practice
Now it is your turn. Here are two vectors:
r = ( 4, 3 )T
s = ( 1, 2 )T
t = r + s
Do it by column matrix addition, and by the head-to-tail rule. In the applet, put the mouse pointer on
the point where you wish to start an arrow, left-click and drag to the point where you wish the arrow
to end.
QUESTION 13:
t = (5, 5)T
Same Problem
Now add up the vectors in the opposite order: form the sum
t = s + r
where
r = ( 4, 3 )T
s = ( 1, 2 )T
Do this by adding two new arrows to the above diagram. (Remember, vectors have no location, so it
is OK to have several arrows in a diagram for the same vector.)
QUESTION 14:
As before,
T = (5, 5)T
T = S + R
T = R + S
where
R = ( 4, 3 )T
S = ( 1, 2 )T
There are two ways to draw the diagram, depending on which arrow's tail you put at the origin. If you
draw both versions, then you get a parallelogram with the sum of the vectors as the diagonal arrow
who's tail starts at the origin.
What is a parallelogram? you might ask, if your high school geometry is a bit murky. A
parallelogram is a four sided figure with opposite sides parallel and equal in length. So, for example,
the blue arrows representing the vector s are the same length and same direction. The green arrows
representing the vector r have their same length and same direction.
QUESTION 15:
w = ( -2, -3 )T
More Practice
Now draw u, v, and w on the graph paper, where, as before, u = ( -3, 2 )T, v = ( 1, -5 )T, and
w = ( -2, -3 )T
QUESTION 16:
Now consider an ant that starts at the origin and walks along vector u, then walks along vector v, to
end up at the tip of w.
A second ant starts at the origin and walks along vector w to its end. Both ants end up at the same
point.
QUESTION 17:
No. In this case, it is clear that walking in a straight line to the final destination is shorter.
Here is a case where the length of the sum is much shorter than the sum of the lengths:
e = ( 5, 4 )T
g = ( -4.9, -3.9 )T
e + g = ( .1, .1 )T
(For clarity g has been moved slightly moved away from where it should be.)
QUESTION 18:
Can you think of a situation where the length of the result is equal to the sum of the length of the two
input vectors?
Can you think of a situation where the length of the result is equal to the sum of the length of the two
input vectors?
This will be true if one vector is in the same direction as the other.
For now, to determine if two vectors have the same orientation you have to look at a picture or use
geometry. Later on there will be a procedure to test if two vectors point in the same direction.
This example is a case where the "=" sign in the formula applies:
QUESTION 19:
Can you think of another case in which the "=" sign applies?
Can you think of another case in which the "=" sign applies?
QUESTION 20:
Now consider what this might mean: add the vector (1, 2)T to the point (4, 4)T.
If you think that makes sense, then do the calculation. What type of object is the result?
This is one of the situation where using the same representation (ie. column matrices) for both points
and vectors is confusing. You have to keep track of what type of object each matrix represents.
This is slighly odd. Two mathematical objects of different types are added together. Again, the "+"
sign is overloaded.
Here is a diagram showing the point ( 4, 4 ). Draw the vector (1, 2)T as a displacement from that point
to the sum ( 5, 6 ).
QUESTION 21:
Translation
Sometimes the operation of adding a vector to a point is called translation. The original point is
sometimes said to have been "translated to a new location."
The vocabulary here might be confusing. In mathematical terms, the sum of a vector and a point
yields a new point. The first point remains unchanged. But in computer graphics terms it is nice to
think about pictures "moving across the screen" when displacement vectors are added to their points.
QUESTION 22:
We have seen:
● vector + vector
● point + vector
● point - point
● point + point
The sum of two points does not mean anything, geometrically. The sum of two column vectors that
represent points is possible, mechanically, but is meaningless.
End of Chapter
You have reached the end of this chapter. Perhaps you would like to see if you remember any of it:
The next chapter will further discuss operations on vectors. The chapter after that will discuss further
operations on vectors. The chapter after that will further discuss further operations on vectors. It is
going to be a long semester.
QUESTION 1:
What do you suppose is the length of the vector represented by: (3, 0)T ?
(3, 0)T
QUESTION 2:
a = (0,4)T is aligned with the Y axis. Its length, 4 units, can be read off the diagram.
Pythagorean Formula
Of course, vectors have no fixed location, so vector a can
be drawn anywhere. The diagram shows the vectors of
length 3 and 4, and with a new vector, h.
(length of hypoteneuse)2 =
(length of first side)2 + (length of
second side)2
(length of hypoteneuse)2 = 32 + 42
(length of hypoteneuse)2 = 9 + 16 =
25
(length of hypoteneuse) = 5
QUESTION 3:
What is the length of the hypoteneuse of a right triangle whose two sides are 6 and 8?
What is the length of the hypoteneuse of a right triangle whose two sides are 6 and 8?
length2 = 6 2 + 82
length2 = 36 + 64 = 100
length = 10
QUESTION 4:
The length is 5.0. You could use the formula, or by realize that this is another 3-4-5 right triangle.
length of ( a ) = | a |
Your browser might not show this well. The symbol a has a vertical bar on each side. Sometimes
books will use two vertical bars on each side. Using the new notation:
| (x, y)T | = ( x2 + y2 )
QUESTION 5:
Notice that the length is NOT 1.0, nor 2.0. People sometimes make that mistake if they are not
careful.
| u + v | <= | u | + | v |
u = (3, 4)T
v = (3, -4)T
w = u + v = (6, 0)T
QUESTION 6:
What is | u |, | v |, and | w | ?
u = (3, 4)T | u | = 5
v = (3, -4)T | v | = 5
w = u + v = (6, 0)T | w | = 6
Another Example
That was too easy. Usually vector elements are not
convenient integer values. Here are some more realistic
vectors, represented by the column matrices:
q = (2.2, 3.6)T
r = (-4.8, -2.2)T
s = q+r
| (x, y)T | = ( x2 + y2 )
But now you will have to get out a calculator (or click on
the calculator in Windows).
QUESTION 7:
What is | q |, | r |, and | s | ?
q = (2.2, 3.6)T
r = (-4.8, -2.2)T
s = q+r
Length of 3D Vectors
Three dimensional vectors have length. The formula is about the same. The length of a vector
represented by a three-component matrix is:
For example:
QUESTION 8:
Squaring the elements of the vector results in a sum of all positive values, ensuring a positive (or
zero) value for length.
Geometrical Vectors
Keep in mind that vectors are geometrical objects: a length and a direction in space. Vectors are
represented with column matrices. The formulas for length that have been presented in this chapter
assume that a coordinate frame is being used and that the vectors are represented with column
matrices in that frame.
Your graphics text book will discuss how homogeneous coordinates are used to represent vectors.
That method uses 4-component column matrices to represent vectors in three dimensions. Calculating
the length of a vector represented in that manner will call for a slight modification of the formulas
discussed here.
Don't worry terribly about that now. Details will come soon enough. But do take the time to become
comfortable about the idea that column matrices such as we have been using are not the only way to
represent vectors, and that length is a property of the vector, not of the column matrix that represents
it.
QUESTION 9:
Is the distinction between an object and its representation of any importance in computer science?
Is the distinction between an object and its representation of any importance in computer science?
More Practice
It would be good to practice that
idea. The diagram shows a vector
and two coordinate frames; a light
gray frame and an orange frame.
QUESTION 10:
If you calculate the length of a vector and get a negative number, what must be true?
The only time the length of a 3D vector is zero is when the vector is the zero vector. In all coordinate
frames the 3D zero vector is represented by:
0 = ( 0, 0, 0)T
|0| = ( 02 + 02 + 02 ) = 0
Of course, the length of the 2D zero vector is also zero, and it is the only 2D vector with zero length.
QUESTION 11:
Thought questions:
● Will two vectors that are equal to each other have the same length?
● Will two vectors that have the same length always be equal to each other?
● Will two vectors that are equal to each other have the same length?
❍ --- YES, since corresponding elements must be equal, so corresponding squares must be
QUESTION 12:
What is the relation between the length of v and the length of -v?
What is the relation between the length of v and the length of -v?
| v | = | -v |
Opposite Direction
You can see this mechanically:
You would like to say that the two vectors are the
same length, but point in opposite directions. In fact,
you can say that. The next chapter will give you the
authority to do so.
QUESTION 13:
( 12 + -12 + 12) = 3
Click on a term to see where it was discussed in this chapter. Remember to click on the "Back" arrow
of your browser to get back to this page. The next chapter will discuss the direction of a vector.
QUESTION 1:
(4, 0)T
(4, 0)T
The vector is parallel to the X axis of the coordinate frame we are using. Often this is horizontal,
pointing right. (Or, you might have said that the vector is oriented at 0 degrees.)
QUESTION 2:
(change in y)/(change in x) =
4.0/4.0 = 1.0.
QUESTION 3:
arc tan( y/x ) = arc tan( 4/3 ) = arc tan( 1.333333333333 ) = 53.13o
Look at the pictue to see that the orientation of -k (expressed in degrees 0--360 counter clockwise
from the x axis) is 180o + 53.13o = 233.13o.
QUESTION 4:
What is the orientation of the vector represented by: p = (3,-4)T ? Use the calculator application on
your computer.
arc tan( y/x ) = arc tan( -4/3 ) = arc tan( -1.333333333333 ) = -53.13o
QUESTION 5:
What is the orientation of u = (-4, -2)T ? (Sketch the vector first, then use a calculator.)
By plugging into the formula (and using inv tan of the MS Win calculator):
arc tan( y/x ) = arc tan( -2/-4) = arc tan( 0.5 ) = 26.565 degrees
...But from the sketch, this is in the wrong quadrent. If you study the sketch and use geometry, you
realize that the complete answer must be (180 + 26.565 )o = 206.565o.
| (x, y)T | = ( x2 + y2 )
QUESTION 6:
Sketch the vector r represented by (4, 5)T. Make an eyeball estimate of its length and direction. Then
do the math to get the exact answer.
1. Draw a sketch.
2. Calculate x by projecting the length onto the x-axis
(usually length*cos( ) )
3. Calculate y by projecting the length onto the y-axis
(usually length*sin( ) )
4. Check answers against the sketch.
QUESTION 7:
A vector has length 4 and orientation 150o. Express the vector as a column vector.
A vector has length 4 and orientation 150o. Express the vector as a column vector.
Radians
The steps in this calculation are:
1. The argument for sin(), cos(), tan() is expected in radians. The return value of atan() is in
radians.
2. The argument for most math functions is expected to be a double. If you supply a float or an
int, you won't get a error message, just a horribly incorrect answer.
3. There are several versions of "arc tan" in most C libraries, each for a different range of output
vaues.
Now would be a good time think about radians. Usually in professional circles, angles are expressed
in radians. Angles are measured counterclockwise from the positive x axis (or sometimes a negative
angle is measured clockwise from the positive x axis.
QUESTION 8:
Fill in the blanks so that vector[0] gets the x component and vector[1] gets the y component of the
vector.
#include math.h
#define PI 3.14159265
vector[0] = ________________
vector[1] = ________________
#include math.h
#define PI 3.14159265
(Unfortunately, different compilers use different symbols for PI, and define it it different header files.)
1. Draw a sketch.
2. Calculate x by projecting the length onto the x-axis
(usually length*cos( ) )
3. Calculate y by projecting the length onto the y-axis
(usually length*sin( ) )
4. Check answers against the sketch.
The steps are the same (of course) if the angle is given in radians.
QUESTION 9:
A vector is 4.5 units long oriented at 0.70 radians. Express the vector as ( x, y )T.
A vector is 4.5 units long at 0.70 radians. Express the vector as ( x, y )T.
Lost Bugs
Your
sketch
should
look
something
like the
one at the
left. Now
it is time
for another
story
problem.
Lola the
Ladybug is
lost. Luckily, Lola has a cellular phone and a compass. Lola is located at the point (1, -4). Lulu is
located at the point ( -4, 3),
QUESTION 10:
Call up Lola and tell her in what direction and for what distance she should walk to reach her friend
Lulu. (Usually a compass regards North as zero degrees; ignore this and use our usual method.)
Buggy Directions
To get the answer you had to recall how to calculate
displacement. To calculate the displacement vector
between two points (or bugs):
QUESTION 11:
Will the ideas about 2D vector orientation presented in this chapter work for 3D space?
Not easily. Orientation of 3D vectors will take more work, and another chapter.
Click on a term to see where it was discussed in this chapter. Remember to click on the "Back" arrow
of your browser to get back to this page. The next chapter will discuss the product of a vector and a
scalar. This will be useful in several important applications, such as in quizzes and midterms.
● Scaling.
● Unit vectors.
● Normalizing a vector.
● Variables in vector equations.
QUESTION 1:
Change the elements of this column matrix: (3, 4)T so that the vector it represents is twice as long and
remains pointing in the same direction. (Officially you don't know how to do this. Take a guess.)
Change the elements of this column matrix: (3, 4)T so that the vector it represents is twice as long and
remains pointing in the same direction.
You could carefully work out the correct answer using what you already know. Or you could take a
guess and see if it works: 2 times (3, 4)T = (6, 8)T
Scaling
Does the guess work?
length)
● By similar triangles, the direction is the
same.
Scaling a geometrical vector means keeping its orientation the same but changing its length by a scale
factor. It is like changing the scale of a picture; the distances expand or shrink, but the directions
remain the same.
If a vector is represented by a column matrix (x, y)T then scaling by the a number multiplies each
element:
QUESTION 2:
QUESTION 3:
● -1v
● 0v
● -1v = -v
● 0v = 0
The output of scaling is a vector. The boldface 0 in the last equation is the vector represented by
(0,0,0)T, not the real number zero.
QUESTION 4:
What is:
2 + 4( 3, 2, 5)T
What is:
2 + 4( 3, 2, 5)T
(Trick Question!) The expression is ill-formed. There is no operator + that does this: real number +
vector
The first "+" is scalar addition; the second "+" is column matrix addition. You should perform the
operations like this:
(2 + 1)(3, -5)T + 4(1, 2)T = 3(3, -5)T + 4(1, 2)T = (3*3, 3* -5)T + (4*1, 4*2)T
= (9, -15)T + (4, 8)T = (13, -7)T
This is not as bad as it looks, as long as you keep track of what operators you have available, what
types of operands they take, and what their results are.
QUESTION 5:
More Algebra!
If there is an unknown or two in the mix, you can use algebra in the usual way to solve for them. Just
be careful that each move you make results in a valid expression. For example, solve the following for
a and y:
You might say that this cannot be done, since there are two unknowns (a and y) but only one
equation. However:
a = 2
ay + 10 = 20
2y = 10
y = 5
This last manuever is a very common trick, called equating corresponding elements.
QUESTION 6:
6x-4 = 8
4y+20 = 24
6x = 12; x = 2
4y = 4; y = 1
The "trick" of equating corresponding elements converts a column matrix equation into several scalar
equations, one equation for each dimension of the column matrix. Then, sometimes, the scalar
equations can be solved for the unknowns. But this does not always work.
4x + 2y = 24
22 = 22
The two scalar equations we get by equating corresponding elements do not contain enough
information to proceed.
QUESTION 7:
Find a and x :
a( -1, 5 )T + 2( 3x, 10 )T = ( 8, 25 )T
a( -1, 5 )T + 2( 3x, 10 )T = ( 8, 25 )T
( -a, 5a)T + ( 6x, 20 )T = ( 8, 25 )T
( 6x-a, 5a+20 )T = ( 8, 25 )T
6x-a = 8
5a+20 = 25; 5a = 5; a = 1
a( x, y )T = ( ax, ay )T
( x, y )
-------- = ( x/2, y/2 )
2
QUESTION 8:
1.0
Unit Vector
The vector has a length of one because it is aligned with the x axis (in the current coordinate frame).
When represented by a column matrix its only non-zero element is 1.0. Of course, other vectors, not
aligned with any axis, can have a length of one.
QUESTION 9:
Often this idea is written as a formula (the little subscript "u" is supposed to mean "unit vector"):
vu = v / | v |
vu = v/|v| = ( x / | v |, y / | v |, z / | v | )T
QUESTION 10:
The is the hypotenuse of a 3-4-5 right triangle, so its length is 5. The unit vector is:
QUESTION 11:
1. | w | = (16 + 36) = 52
2. wu = (4, 6)T / ( 52)
A unit vector formed from a three dimensional vector will point in the same direction as the original.
QUESTION 12:
| g | = (9 + 16 + 1 ) = 26
gu = ( -3, 4, -1)T / ( 26)
Opposite Direction
This represents a unit vector oriented at 45o:
QUESTION 13:
Create a unit vector that points in the opposite direction as (3, 0, 2)T.
Create a unit vector that points in the opposite direction as (3, 0, 2)T.
● Definition of scaling.
● Definition of a scalar.
● Some properties of scaling.
● Equating corresponding elements in vector algebra.
● Unit Vectors.
● Normalizing a vector.
● Orientation of a unit vector.
Click on a term to see where it was discussed in this chapter. Remember to click on the "Back" arrow
of your browser to get back to this page. The next chapter will discuss the dot product of two vectors.
This chapter discusses the dot product, which takes two vectors as operands and produces a real
number as its output. Sometimes the dot product is called the inner product. Sometimes the dot
product is called the scalar product, which should not be confused with the operation called scaling
(but probably will be).
QUESTION 1:
QUESTION 2:
Commutative
u · v = v · u.
0 · 0 = 0.
QUESTION 3:
Cosine of 90°
You may be somewhat fuzzy about how the cosine
function behaves. Rather than memorize abstract
stuff, I prefer to visualize the unit circle with its radius
projected onto the x-axis.
Recall that
QUESTION 4:
Two vectors are oriented at 90° to each other. What is their dot product?
Two vectors are oriented at 90° to each other. What is their dot product?
If u and v are orthogonal, then u · v = |u| |v| cos 90° = |u| |v| 0.0 = 0.0
"Orthogonal" means "oriented at 90° to each other". To keep things consistent, the zero vector is
regarded as orthogonal to all other vectors since 0 · v = 0.0 for all vectors v.
QUESTION 5:
Say that two vectors s and t have a dot product that is zero.
Say that two vectors s and t have a dot product that is zero.
The dot product of a vector with itself yields the square of its length, or:
|v| = (v · v)
Used in this fashion, the dot product is a pure length detector. Since the two properties of a vector are
length and orientation, you might suspect that the dot product is useful.
QUESTION 6:
QUESTION 7:
a · b = a1b1 + a2b2
Multiply corresponding elements of each vector, then add up the products. The result is a scalar value.
Sometimes the dot product is written like this: aT b (but it is defined the same way). The reason for
this second, odd notation will be apparent in a later chapter when matrix multiplication is discussed.
Here is an example:
● a = ( 1, 2 )T
● b = ( 3, 4 )T
● then a · b = 1*3 + 2*4 = 3 + 8 = 11
QUESTION 8:
● a = ( 1, 2 )T
● b = ( 3, 4 )T
● What is: b · a ?
● a = ( 1, 2 )T
● b = ( 3, 4 )T
● b · a = 3*1 + 4*2 = 1*3 + 2*4 = a · b
Same Properties
The dot product between column matrices has the same properties as the dot product between vectors.
Here is another example:
1. p = ( -2, 5 )T
2. q = ( 3, -1 )T
3. then p · q = (-2)*3 + 5*( -1) = -6 + -5 = -11
1. s = ( 1.082, -3.224 )T
2. t = ( 2.381, 7.009 )T
3. then s · t = 1.082*2.381 + -3.224*7.009 = 2.576242 + -22.597016 = -20.020774
In all cases the dot product takes two column matrix operands and yields one scalar value.
QUESTION 9:
Form the dot product of: ( -1, 3)T and (2, 4)T.
Form the dot product of: (2, 4)T and ( -1, 3)T.
Commutative
The dot product of column matrices is commutative:
a · b = b · a
As with the dot product of vectors, the order of operands makes no difference. Write out the definition
of dot product for both arrangements of a and b:
(Just in case your eyes have glazed over: notice that the stuff after the last "=" sign is the same in each
case.)
QUESTION 10:
a · b · c
a · b · c
It makes no sense. Remember that the dot product of two vectors (or column matrices) makes a real
number. There is no such thing as the dot product between a real number and a vector (or column
matrix).
or:
When dealing with dot products, keep track of the types of operands and results, as illustrated by the
previous question.
QUESTION 11:
(Notice that there is no "dot" between the 2 and the vector following it, so this means "scaling," not
dot product.)
QUESTION 12:
You must be itching to try this yourself (or is that your allergy to math acting up again?)
This is not a surprise (I hope). We saw the same thing with geometrical vectors.
0 · a = 0
This looks obvious. The first 0 is the zero column matrix; the last 0 is the real number zero. Also,
0 · 0 = 0
In each of these equations the zero column matrix means a column matrix of the same dimension as
the other column matrix, with each element the real number zero.
QUESTION 13:
More practice:
QUESTION 14:
What is:
Alway Positive
As with vectors, the dot product of a column matrix with itself will always be positive.
No matter what x, y, and z are, their square is going to be zero or greater. So the sum is going to be
zero or greater.
The only time the square of a real number is zero is when the real number is zero; so the only time the
dot product of a column matrix with itself is zero is when it is the zero column matrix.
QUESTION 15:
g · g= 0
g = 0 = (0, 0, 0)T
a · (b + c) = a · b +a · c
This looks reasonable, but be careful that you understand what it says. In particular, the "+" on either
side of "=" mean different things.
QUESTION 16:
1. What is the meaning of the "+" on the LEFT side of the equation?
2. What is the meaning of the "+" on the RIGHT side of the equation?
a · (b + c) = a · b +a · c
1. What is the meaning of the "+" on the LEFT side of the equation: Vector Addition.
2. What is the meaning of the "+" on the RIGHT side of the equation: Real Number Addition.
1. Show that: a · (b + c) = a · b + a · c
2. Let a = ( f, g, h)T
3. Let b = ( r, s, t)T
4. Let c = ( x, y, z)T
5. a · (b + c) = a · ( r+x, s+y, t+z )T = f(r+x) + g(s+y) + h(t+z) = fr + fx + gs + gy + ht +
hz
6. a · b + a · c = (fr + gs + ht) + (fx + gy + hz) = fr + fx + gs + gy + ht + hz
7. Both sides of the equation represent the same real number.
The same demonstration could be done with vectors of any dimension, so the distributive property is
true for any dimension.
QUESTION 17:
It is probably easiest NOT to re-arrange the expression, but to do the vector addition first:
( -2, 1, 2)T · ( (3, -1, 4)T + ( -2, 1, -2)T ) = ( -2, 1, 2)T · (1, 0, 2)T
QUESTION 18:
Click on a term to see where it was discussed in this chapter. Remember to click on the "Back" arrow
of your browser to get back to this page. The next chapter will discuss how the dot product relates to
the length of a vector.
QUESTION 1:
Let v = ( 3, 4 )T
1. v · v = ?
2. The length of v = ?
Let v = ( 3, 4 )T
1. v · v = ?
❍ ( 3, 4 )
T · ( 3, 4 )T = 32 + 42 = 9 + 16 = 25 = 52
2. The length of v = ?
❍ The length of the vector is 5.
v · v = | v |2
The dot product of a column matrix with itself is a scalar, the square of the length of the vector it
represents.
WARNING! When your graphics text starts using homogeneous coordinates this calculation will
need to be modified somewhat. Remember, length is a property of the geometric vector, not an
inherent property of the column matrix that might be used to represent it.
QUESTION 2:
Practice
Here are some easily confirmed facts:
QUESTION 3:
Unit Vectors
Recall that a unit vector is a vector of length one. Creating a unit vector in the same direction as a
given vector is called normalizing the vector. Here is the formula for normalizing a vector (copied
from a previous chapter):
vu = v / | v |
The formula works when column matrices are used to represent the vector. The length | v | is
frequently calculated by using the column matrix dot product.
Potential Confusion: The word "normal" has several meanings. Normalizing a vector means making
a unit vector in the same direction as the original. A vector that is perpendicular to a particular surface
is sometimes called a "normal vector" but is not necessarily a unit vector. Be careful never to say
"normal vector" when you mean "unit vector."
QUESTION 4:
( 1.2, -4.2, 3.5 )T · ( 1.2, -4.2, 3.5 )T = 1.22 + (-4.2)2 + 3.52 = 31.33.
QUESTION 5:
Answer the following questions. (You might want to think of 2D vectors when you answer, although
the answers will be correct for 3D vectors as well).
The same is true for other orientations and other number of dimensions. The picture shows vectors of
various lengths but same orientation. Only one of them is a unit vector.
This formula is not very useful in three dimensions, where there are three axes and it is not enough to
determine the angle between a vector and just one of them.
Often the unit vector corresponding to a given vector is used to express the given vector's direction.
There is only one corresponding unit vector, so this description of direction is unique. This works for
all dimensions.
QUESTION 6:
1. | v |2 = 9 + 4 + 16 = 29
2. vu = v / 29
Right Angles
It is interesting when the directions of two
vectors are 90o apart. For example, zero
degrees and 90 degrees.
QUESTION 7:
QUESTION 8:
(Yes, I know, this looks an awful lot like trigonometry. But it isn't. Just do it.)
Plugging away:
The dot product of two orthogonal vectors is zero. The dot product of the two column
matrices that represent them is zero.
Only the relative orientation matters. If the vectors are orthogonal, the dot product will be zero. Two
vectors do not have to intersect to be orthogonal. (Since vectors have no location, it really makes little
sense to talk about two vectors intersecting.)
QUESTION 9:
● q = ( -5, 3 )T
● r = ( 3, 5 )T
● q = ( -5, 3 )T
● r = ( 3, 5 )T
Independent of Length
To form a 2D column matrix that is perpendicular to an other:
This only works in 2D, however. It gives you one of an infinite number columns orthogonal to the
given one. For example, all the following vectors are orthogonal to ( -5, 3)T:
● ( 3, 5 )T
● ( -3, -5)T
● ( 1.5, 2.5)T
● ( 6, 10)T
● .... and so on
The reason this is so is: If u is orthogonal to v, then u · v = 0. So (ku) · v = k(u · v) = 0, for any
real number k. So there are an infinite number of vectors (ku) orthogonal to v.
Often one wishes to find a unit normal to a given vector. A unit normal to a given vector is a vector
that:
Remember not to confuse the two ideas normalizing a vector (making a unit vector in the same
direction as the vector), and computing a unit normal (making a unit vector in an orthogonal direction
to a vector.)
QUESTION 10:
(3, 5)/( 34). Or you might pick the other one (there are two): (-3, -5)/( 34).
QUESTION 11:
● ( 0, 0, 0 )
● ( -2, 1, 0 )
● ( 0, -1, 1 )
● ( -4, 1, 1 )
● ( 0, 1, -1 )
● ... and infinitely many more
These are all normal to the given vector because their dot product with it is zero. These are not unit
normals. But even if you were to insist on unit normals, there would still be an infinite number.
From analytic geometry you may recall the formula for the slope of a line in two dimensions not
parallel to the Y axis:
m = (change in y) / (change in x)
This is the same formula as for the tangent of the angle with the x axis. This formula is related to the
reason that the dot product of orthogonal 2D vectors is zero.
QUESTION 12:
If two lines are perpendicular, then the product of their slopes is -1.
This is another way to look at what goes on when you make a normal vector to a given 2D vector by
swapping elements and negating one:
● If v = ( x, y )T
● Then v' = ( -y, x )T is orthogonal,
● because ( x, y)T · ( -y, x ) is -xy + yx = 0.
● The slope of ( x, y )T is y/x.
● The slope of ( -y, x )T is -x/y.
● The product of the slopes is y/x * -x/y = -(xy)/(xy) = -1
QUESTION 13:
You have reached the end of the chapter. Normally at this point you would review the following
terms:
Click on a term to see where it was discussed in this chapter. Remember to click on the "Back" arrow
of your browser to get back to this page.
In the first case, the angle between the vectors and itself is 0°. In the second case, the angle between
the two vectors is 90°.
QUESTION 1:
Does the angle between two vectors have something to do with the dot product?
Yes---maybe the dot product is large when the angle is close to zero and small when the angle is close
to perpendicular.
QUESTION 2:
● a is (6, 0)
● b is (3, 1.9)
● c is (5, 9)
● a · b is 15.0
● a · c is 30.00
QUESTION 3:
Normalize Vectors
QUESTION 4:
● a · b , or
● a·c ?
Hint: remember that u · v = |u| |v| cos . But here both vectors have length 1.0.
Since u · v = |u| |v| cos and all vectors in this problem have length 1.0, u · v = cos . The
dot product of au · bu is the cosine of the angle between au and bu, which can be read off the diagram
as 0.866.
The dot product of au · cu is the cosine of the angle between au and cu, which can be read off the
diagram as 0.500.
● au · bu is 0.866
● au · cu is 0.500
QUESTION 5:
What do you suppose happens when the vectors are in opposite directions, such as (1, 0)T and (-1, 0)T
?
What do you suppose happens when the vectors are in opposite directions, such as (1, 0)T and (-1, 0)T
?
The bu in each case is the unit vector represented by (cos , sin )T.
QUESTION 6:
What do you imagine is the range of values for the dot product of two unit vectors, au · bu ?
au · bu = cos
where is the angle between the two vectors. This formula automatically includes the fact that the dot
product of perpendicular vectors is zero (because cos 90° is zero).
QUESTION 7:
What is the cosine of the angle between the two unit vectors (0.7071, 0.7071)T and (0.5, 0.866)T ?
(You may wish to use the desktop's calculator for this).
What is the cosine of the angle between the two unit vectors (0.7071, 0.7071)T and (0.5, 0.866)T ?
Practice
The first vector, (0.7071, 0.7071)T is a unit vector at 45°.
The second vector, (0.5, 0.866)T is a unit vector at 60°.
So the dot product should be the cosine of 15°, which it
is.
sin2x + cos2x = 1
QUESTION 8:
What is the cosine of the angle between the two unit vectors qu = (0.0, 1)T and ru = (0.5, 0.866)T ?
More Practice
The picture shows qu and ru and the angle between
them.
QUESTION 9:
What is the cosine of the angle between the two unit vectors qu = (0.0, 1)T and wu = (-0.5,
0.866)T ?
What is the cosine of the angle between the two unit vectors qu = (0.0, 1)T and wu = (-0.5,
0.866)T ?
Which Side?
Both vectors ru and wu gave the answer cos 30, when the
dot prodcut was done with qu, although they lie on either
side of qu.
In two dimensions, there are two unit vectors that are 30°
away from a given vector. Both of them will give you the
same dot product with the given vector. Be careful to
draw a picture in ambiguous situations.
QUESTION 10:
What is the cosine of the angle between the two unit vectors qu = (0.0, 1)T and zu = (-0.5, -
0.866)T ?
QUESTION 11:
In the diagram above, mentally draw the other vector that has a dot product of -0.866 with vector qu.
● zu = (-0.5, -0.866)T
● vu = ( 0.5, -0.866)T
QUESTION 12:
What is the angle between these two vectors: du = 0.7071(1, 1)T and eu = -0.7071(1, 1)T
What is the angle between these two vectors: du = 0.7071(1, 1)T and eu = -0.7071(1, 1)T
so the angle is: arc cos( -1 ) = 180°. In 2D, there is only one vector 180° away from a given
vector.
More Practice
Of course, the real world rarely gives you easy angles of 30°, 45°, 60°, and so on. Here is a more
realistic problem: Find the angle between:
● fu = (0.6, 0.8)T
● gu = (0.8, 0.6)T
You may wish to confirm that these are indeed unit vectors. Now, sketch the vectors. Then, calculate
their dot product. Use the arc cos function of the desktop calculator (or a real calculator) to find the
angle. Calculate the answer in degrees, not radians.
QUESTION 13:
Non-unit Vectors
● j = (3, 4)T
● k = (0, 2)T
These are not unit vectors, so you can not find the angle
between them without further work. As always, draw a
sketch first.
QUESTION 14:
What do you suggest doing, so that the angle between the two vectors can be found?
Normalize each vector. This does not change the orientations. Now there are two unit vectors and the
cosine of the angle between them can be found with the dot product.
Compute the dot product: (3, 4)T /5.0 · (0, 2)T / 2.0 =
(1/10)(3, 4)T · (0, 2)T = (0.1)(8) = 0.8.
QUESTION 15:
(10, 5)T/ 125 · (8, 12)T/ 208 = (10*8 + 5*12) / ( 125 208)
= 140 / ( 125 208) = 140/ (125*208)
= 140/ 26000 = 0.86824
Click on a term to see where it was discussed in this chapter. Remember to click on the "Back" arrow
of your browser to get back to this page.
This chapter adds nothing new, but further elaborates the third application by discussing the angle
between vectors in 3D space.
QUESTION 1:
What is the angle between two edges of a cardboard box that meet in a corner?
What is the angle between two edges of a cardboard box that meet in a corner?
90°
QUESTION 2:
If our viewpoint changes, do the angles between the edges of the box change?
If our viewpoint changes, do the angles between the edges of the box change?
No. The orientations and lengths of the edges are 3D vectors. Changing our viewpoint does not
change them.
au · bu = cos
QUESTION 3:
Apply this formula to the two unit vectors parallel to the x axis and y axis (in the coordinate frame we
happen to be using): (1,0,0)T and (0,1,0)T.
(1,0,0)T · (0,1,0)T = 0. Therefore the x and y axis are orthogonal. (As we expected).
The angle between the two vectors is not 90°, and so is harder to see than in the previous example.
Click on the right and left rotate buttons to get a better idea of the angle.
QUESTION 4:
Take a guess: what angle is between a and b? 10° ? 35° ? 70° ? 120° ?
Visually, it looks somewhat less than midway between perpendicular and horizontal. 35° would be a
good guess.
The formula for the angle between two unit vectors is:
au · bu = cos
To use this formula with non-unit vectors: (1) normalize each vector, (2) compute the dot product, (3)
take the arc cos to get the angle.
QUESTION 5:
● f = (4,3,2)T
● g = (-1,4,4)T
Rotate the figure to get a better sense of the angle. What you would like to do is to lay a sheet of
paper across the two vectors, trace them onto the paper, and then measure the angle with a
protractor. But this is hard to do with a computer screen.
QUESTION 6:
Guessing, however, is easy. About what angle separates the two vectors?
After rotating them figure a few times, I guessed 50°. But this is only a guess.
QUESTION 7:
Do two vectors need to be touching at their tails for there to be an angle between them?
Do two vectors need to be touching at their tails for there to be an angle between them?
No---remember vectors don't really have a position. You can take the dot product of any two 3D
vectors or the column matrices that represent them.
QUESTION 8:
To catch the most rays, your back should be pointed straight at the sun. You want the smallest angle
between the perpendicular to your back and the direction to the sun.
For Bob: ( -1, 2, 2)/3 · ( -3, 4, 0)/5 = (3+8+0)/15 = 11/15. arc cos( 11/15 ) = 42.8 degrees
For Bill: ( -2, 1, 2)/3 · ( -3, 4, 0)/5 = (6+4+0)/15 = 10/15. arc cos( 14/15 ) = 48.2 degrees
More Practice
The diagram shows two more example vectors:
q = (-2, 4, 3)T
p = (3, 1, -4)T
For ease in visualization the tails of the vectors have been placed at the origin. The vectors point
into two different octants of 3D space.
Rotate the viewpoint to get a better idea of the two vectors. See if you can find a viewpoint that best
shows the angle between the vectors.
QUESTION 9:
What is the angle between the two vectors? (Work it out numerically.)
120.654 degrees
QUESTION 10:
s = (1, 0, 1)T/ 2
t = (1, 1, 1)T/ 3
s = (1, 0, 1)T/ 2
t = (1, 1, 1)T/ 3
cos = (1, 0, 1)T · (1, 1, 1)T / ( 2 3) = 2/( 2 3) = 2 / 3 = 0.8164
Geometry
The dot product formula can be used to work out some geometric problems that otherwise
would be hard. In the following figure, the red edges of the figure coincide with the
coordinate axes. They share a mutual endpoint at (0, 0, 0). The edge along the x axis ends at
x=2; the edge along the y axis ends at y=3; and the edge along the z axis ends at z=4. The
remaining edges connect these endpoints. Now say that you wanted to calculate the angle
between the two green edges. This might be fairly tedious using trigonometry. But now you
can:
QUESTION 11:
60.051°
QUESTION 12:
If you had calculated the displacement vectors in the opposite manner (by subtracting from (0, 3, 0) )
would it have affected the answer?
No--the vectors would point in opposite directions, but their dot product would be the same.
● The formula for the cosine of the angle between unit vectors.
● List of steps to take in applying it to non-unit vectors.
● Using vectors for problems in solid geometry.
Click on a term to see where it was discussed in this chapter. Remember to click on the "Back" arrow
of your browser to get back to this page.
Producing a 2D image from a 3D image is an example of projection. This chapter discusses the
fundamental notions of projection. The advanced topics are left for your graphics text book.
Chapter Topics:
● Projections in general.
● Projecting on vector onto another.
● Example vector projections in 2D.
● Example vector projections in 3D.
QUESTION 1:
QUESTION 2:
Will any two vectors (not co-linear, and neither one the zero vector) lie in a unique plane?
Yes.
QUESTION 3:
Does the scaled vector kv (where k is a scalar) have the same orientation as v?
w = kv + u
QUESTION 4:
Solving for kv
We want: w = kv + u, with the condition that
u is orthogonal to v. Using trigonometry:
kv = | w | (wu · vu) vu
| w | (wu · vu)
QUESTION 5:
Projection Procedure
Rather than memorize the formula for
projection, follow what it means step-by-step.
To project w onto v:
QUESTION 6:
The vector resulting from a projection is oriented in the direction of the vector projected onto.
Finding u
After you have found kv it is easy to find the orthogonal vector, u:
w = kv + u, so u = w - kv
In the above formula, "+" means vector addition and "-" means vector subtraction.
So far in this chapter the vectors have all been geometrical vectors. There has been no mention of
coordinate frames or column matrices.
QUESTION 7:
Will the results of this chapter work when vectors are represented with column matrices?
Will the results of this chapter work when vectors are represented with column matrices?
Thankfully, yes.
Example
Time for an example. In the diagram the answer can simply be read off the graph paper. But pretend
you didn't notice that.
The vector w is represented by by (6, 5)T. The vector v is represented by by (9, 0)T. Find kv and u.
The result is that u = (6, 0)T + (0, 5)T, as expected. Of course, the example was easy.
QUESTION 8:
Another Example
You don't have to compute the length of w, | w |. It cancels out before the final answer. And, all you
need is the square of the length of v, | v |2. Some books show formulae for projection that make use of
these facts (but, to my taste, are less intuitive).
The diagram shows another example, this time not so easy. The vector w is represented by by
(3.2, 7)T. The vector v is represented by by (8, 4)T. Find kv and u.
QUESTION 9:
Is w = kv + u, as it should?
But you are not going to make your living actually doing
the calculations.† And I have a headache from setting all
those equations in HTML. So let's skip the math and just
read off the answer from the diagram.
†A friend of mine does make a living doing projections. But he does it from a projection booth in a movie theater, and
even that job is being taken over by computers.
QUESTION 10:
First: Does w = kv + u?
QUESTION 11:
Think about all possible vectors w and v and the projection of w onto v.
QUESTION 12:
To make this example especially hard, I've changed the colors. Project w onto v by examining the
diagram.
Eyeball Estimate
Those answers were done by reading off the picture. No
guarantee that they are accurate. So let us check:
First: Does w = kv + u?
QUESTION 13:
QUESTION 14:
Mentally project w onto v. (Hint: remember that the length of v does not matter; only its orientation.
So mentally "drop" the arrowhead of w onto the dotted line).
The projection of w = (4, 2.5, 2.5)T onto v = (5, 0, 3.1)T is kv = (4, 0, 2.5)T
So the visual estimate kv = (4, 0, 2.5)T matches the mathematical result, ( 4.00, 0, 2.49)T. The
orthogonal vector can easily be computed:
u = w - kv
u = (4, 2.5, 2.5)T - (4, 0, 2.5)T = (0, 2.5, 0)T
QUESTION 15:
Keep the same vector w as in the diagram. Visualize projecting w onto various vectors v'. Can you
think of a vector v' that results in a projection kv' that collapses both the y and z dimensions of w ?
Keep the same vector w as in the diagram. Visualize projecting w onto various vectors v'. Can you
think of a vector v' that results in a projection kv' that collapses both the y and z dimensions of w ?
It is probably harder to read the question than to figure out the result. If w = (4, 2.5, 2.5)T is projected
onto v' = (1, 0, 0)T the result is kv = (4, 0, 0)T
Another Example
QUESTION 16:
My visual estimate is that if you "drop" the arrow head of w along a perpendicular to v, you hit v at
about 4/10 the length of v. So k is about 0.4 and kv = 0.4 (6, 4, 2)T = (2.4, 1.6, 0.8)T
It turns out that I was grossly wrong. Hope you did better.
QUESTION 17:
The projected future is really grim. More of this stuff. You are sure to get cross.
created: 08/17/00
Chapter Topics:
The most important use of the cross product in computer graphics is to find a vector perpendicular to
a plane.
QUESTION 1:
QUESTION 2:
In the above, is there a multiplication-like operation that takes two vector operands and outputs a vector result?
No.
If u and v are vectors in three dimensional space (only), then u × v is a three dimensional vector,
where:
Length:
|u × v | = | u | | v | sin , where is the angle between u and v.
Orientation:
u × v is perpendicular to both u and v. The choice (out of two) orientations
perpendicular to u and v is made by the right hand rule.
To find a vector perpendicular to a particular plane, compute the cross product of two vectors in that
plane. But there are two directions perpendicular to the plane. Which one does the cross product give
you? That is determined by the right hand rule, which will be explained shortly.
QUESTION 3:
A wood screw is positioned perpendicular to a plank of wood. You wish drive the screw into the
wood with a screw driver. Which direction must you twist the screw driver?
A right-handed screw (the normal kind) must be turned clockwise into the wood (viewed from its
head).
Carpentry of Vectors
The cross prod
vectors is perp
both; the right
picks the one o
possible perpe
directions.
The diagrams
hand rule. The
operands is im
result of u ×
the same direc
must point if t
u to v drives it
Or, think of th
your thumb po
fingers curl ar
v.
QUESTION 4:
Does u × v point in the same direction as v × u ? (Hint: get out your screw driver).
No. The two possible cross products between u and v point in opposite directions.
QUESTION 5:
What angle between u and v will maximize their cross product? (Hint: look at the diagram)
90°
So, u × v = -(v × u) .
QUESTION 6:
Does -(v × u) = -v × u ? (Decide this by looking at the diagram and visualizing both sides of the
equation).
Yes, -(v × u) = -v × u
Colinear Operands
The length of u × v is | u | | v | sin . If u and v are colinear (parallel) what is the length of their cross
product?
Since sin = 0 when = 0 , and the angle between colinear vectors is zero, the magnitude of the
result is zero. The result is still a vector; it is the zero vector 0.
u × u = 0.
(ku) × u = 0.
QUESTION 7:
u×0 = 0×u = 0
QUESTION 8:
What is (ku) × v ?
Not Associative
Fussing with math gives the same result:
The magnitude is | k | times the magnitude of u × v. And the orientation of the result must be the
same. So the answer is correct.
QUESTION 9:
More Properties
Another property is u × (v + w) = u ×
v + u × w . To see this, plug into the
definition of the cross product.
i×j = k i × k = -j
j×k = i k × j = -i
k×i = j j × i = -k
QUESTION 10:
i×i =
j×j =
k×k =
i×i = 0
j×j = 0
k×k = 0
Then u × v = ( uj vk - uk vj , uk vi - ui vk , ui vj - uj vi )T.
There is a pattern in how this is formed. Look at it a bit. But don't even think of memorizing it.
QUESTION 11:
(1, 2, 3)T × (0, 0, 0)T = ( 2×0 - 3×0, 3×0 - 1×0, 1×0 - 2×0 )T = 0
Memory Aid
Here is a way to compute the cross product by arranging the elements of each vector into a
determinant. The top row contains the symbols that stand for each axes. This is not the definition of
cross product. In fact, it is not even a determinant. It is merely a memory aid.
This only works for three dimensional vectors (recall the cross product not defined for vectors of any
but three dimensions). Be careful to put the first vector's components into the second row, and the
second vector's components into the third row.
QUESTION 12:
What is the cross product of (1, 2, 1)T with (0, -1, 2)T ? Fill in the blanks:
What is the cross product of (1, 2, 1)T with (0, -1, 2)T ?
To evaluate a cofactor, multiply the two elements on the main diagonal, subtract from that the product of the
two elements on the other diagonal. For example, for the cofactor of i this is 2×2 - 1×(-1) = 2 + 1 = 5
QUESTION 13:
What is the cross product of (0, -1, 2)T with (1, 2, 1)T ? Fill in the blanks. (NOTE: the order of the vectors has
been reversed).
What is the cross product of (0, -1, 2)T with (1, 2, 1)T ?
Another Evaluation
Evaluation follows the same pattern as before, but the second and third rows have been swapped.
u × v = -(v × u) .
QUESTION 14:
What does the determinant-like thing look like when you take the cross product of a vector by itself?
What does the determinant-like thing look like when you take the cross product of a vector by itself?
The same will happen if one row is a multiple of another. These results reflect what we have already
seen with geometrical vectors: ku × u = 0.
The other properties of the cross product of geometrical vectors are also true of the cross product of
their column matrix representations.
QUESTION 15:
Here is a list:
End of Chapter
Right hand rule.
The orientation of u×v is in the "thumb" direction if your fingers curl from u to v.
Magnitude of Cross product.
The magnitude of u×v is the area of the parallelogram defined by the two vectors.
Anti-commutative
u × v = -(v × u)
Co-linear operands yield zero vector.
u×u = 0 (ku) × u = 0.
Cross product with zero vector yields zero vector.
u×0 = 0×u = 0
Not associative
In general: (u × v) × w =/= u × (v × w)
Distributive over vector addition
u × (v + w) = u × v + u × w
Cross product between coordinate axes
i×j = k j×k = i k×i = j
Chapter Topics:
QUESTION 1:
A column matrix consists of a single column of numbers. Do you think that numbers could be
arranged into a several rows and columns?
Yes. For a computer science student, the answer is obvious. Numbers are often put into a two-
dimensional array.
Definition of Matrix
A matrix is a collection of numbers arranged into a fixed number of rows and columns. Usually the
numbers are real numbers. In general, matrices can contain complex numbers but we won't see those
here. Here is an example of a matrix with three rows and three columns:
The top row is row 1. The leftmost column is column 1. This matrix is a 3x3 matrix because it has
three rows and three columns. In describing matrices, the format is:
rows X columns
Each number that makes up a matrix is called an element of the matrix. The elements in a matrix have
specific locations.
The upper left corner of the matrix is row 1 column 1. In the above matrix the element at row 1 col 1
is the value 1. The element at row 2 column 3 is the value 4.6.
QUESTION 2:
Matrix Dimensions
The numbers of rows and columns of a matrix are called its dimensions. Here is a matrix with three
rows and two columns:
Sometimes the dimensions are written off to the side of the matrix, as in the above matrix. But this is
just a little reminder and not actually part of the matrix. Here is a matrix with different dimensions. It
has two rows and three columns. This is a different "data type" than the previous matrix.
QUESTION 3:
Square Matrix
In a square matrix the number of rows equals the number of columns. In computer graphics, square
matrices are used for transformations and are very common.
Some books call a column matrix a column vector and call a row matrix a row
vector. This is OK, but can be ambiguous. In these notes the word vector will
be used for a geometric object (a directed line segment). In these notes, column matrices will be used
to represent vectors and will also be used to represent geometric points.
QUESTION 4:
Chapter Topics:
QUESTION 1:
What type of object (do you suppose) is the result of a matrix times a column matrix?
What type of object (do you suppose) is the result of a matrix times a column matrix?
The details of how this is done will be explained later. For now, look at the dimensions of the
operands and of the result. A matrix times column matrix product can be formed if the dimensions
look like this:
R x N N x 1 = R x 1
--------
same
2 x 2 2 x 1 = 2 x 1
--------
same
Remember that the order of the dimensions is "Row x Column" so that an R x 1 matrix is a column
matrix (because it has 1 column).
QUESTION 2:
5 x 5 5 x 1 = ? x ?
5 x 5 5 x 1 = 5 x 1
More Practice
For each row in the following table, decide if the matrix times column matrix product can be formed
and what the dimensions of the result will be.
3x2 2x1 ?
2x3 2x1 ?
4x3 3x1 ?
3x5 5x1 ?
QUESTION 3:
Do you think that it is possible to form a product that looks like this:
2 x 1 2 x 2 = ???
Do you think that it is possible to form a product that looks like this:
2 x 1 2 x 2 = ???
N x M M x 1 = N x 1
----------------
inner dimensions
are equal
QUESTION 4:
Do you think that it is possible to form a product that looks like this:
1 x 2 2 x 1 = 1 x 1
revised 08/01/00
Chapter Topics:
Matrix-matrix products are used in computer graphics to create the transformation matrices that
operate on points and vectors. In a "first person game" such as DOOM the landscape is modeled with
points and vectors. The constantly changing view you see as the hero moves through the landscape is
created by transforming those points and vectors.
QUESTION 1:
Look at the dimensions in the following product (for now, ignore how the elements were calculated):
The the product AB (if it can be formed) has the same number of rows as A and the same number of
columns as B. You can think of this as "canceling" the inner dimension.
QUESTION 2:
It always pays to check the dimensions of the result before you do the arithmetic. For example, the
last product (in the table) is a bit odd, and it is easy to get mixed up without knowing what the result
should look like.
QUESTION 3:
If the product An×m Bm×p can be formed, will it always be possible to form the product Bm×p An×m?
If the product An×m Bm×p can be formed, will it always be possible to form the product Bm×p An×m?
No. If n =/= p then BA can't be formed. Later you will see that even if both products can be formed, it
is rare that AB = BA.
As in the previous chapter, flip a column of B so that its elements align with the rows of A. Form the
dot product, which becomes row 1 col 1 of the result. Now slide down one row to form the next dot
product, which becomes row 2 col 1 of the result. Continue down until the last row.
When you are finished with first column of B, move on to the next column and do the same thing.
Continue with each column of B until all elements are calculated.
QUESTION 4:
Say that you are forming the product A5×3 B3×2 = C5×2
What row and column are used to calculate the 3rd row 2nd column of C ?
revised 08/01/00
Chapter Topics:
● Identity Matrix.
● Matrix Inverse.
● Singular and non-singular Matrices.
● Determinant of a Singular Matrix.
QUESTION 1:
A square matrix is one where the number of rows equals the number of columns.
Square Matrices
Computer graphics uses square matrices almost exclusively. Most transformations, such as changing
the point of view in a 3D world or projecting it onto a 2D screen involve square matrices.
Square matrices have properties that are not in general shared by other rectangular matrices. To get a
taste of one of these properties, perform the following multiplication:
A I = C
1 2 1 0
=
-2 1 0 1
Try changing some of the elements of A (don't change elements of I) and try the product again. Only
integer elements will work in this demonstration.
QUESTION 2:
AI = A
Pre-multiplication by I
Now perform the following multiplication.
I A = C
1 0 1 2
=
0 1 -2 1
Try changing some of the elements of A (don't change elements of I) and try the product again. Only
integer elements will work in this demonstration.
QUESTION 3:
IA = A
Identity Matrix
There is no unique matrix that works as an identity for matrices of all dimensions. Instead, for each
set of square matrices of dimensions N×N there is a matrix IN×N that works as an identity.
If IN×N is the N-dimensional identity matrix, then its elements are 1 on the main diagonal and 0
elsewhere.
The 1s must run down that particular diagonal; it won't work with the other diagonal. For square
matrices of dimension n:
The identity matrix works like the identity of scalar arithmetic, the value one: 1a = a1 = a.
QUESTION 4:
INDEX
ABCDEFGHIJKLMNOPQRSTUVWXYZ
A
● addition, column matrix
● addition, of matrices
● addition, point + vector
● addition, zero matrix
● angle between non-unit vectors
● angle between two 3D non-unit vectors
● angle between two 3D unit vectors
● angle, between unit vectors
● associative property, vector addition
C
● column matrix
● column matrix addition, associative
● column matrix addition, commutative
● column matrix flipping in matrix product
● column matrix subtraction, non-commutative
● commutative property, vector addition
● computer graphics, activities
● conformant, matrices
● conformant, matrices
● coordinate frame
● cosine, and unit circle
● cosine, angles which yield negative values
● cross product, anti-commutative
D
● determinant
● determinant of singular matrix
● determinant, evaluation
● determinant, two rows the same
● dimensions
● displacement
● displacement, formula
● dot prodcut, column matrix with self
● dot product of column matrices
● dot product, 3D column matrices
● dot product, affected by vector properties
● dot product, ambiguous orientation
● dot product, and length
● dot product, and vector length
● dot product, as matrix product
● dot product, column matrices, distributive
● dot product, column matrix, commutative
● dot product, column matrix, properties
● dot product, commutative
● dot product, definition
● dot product, of orthogonal vectors
● dot product, properties
E
● element
● equality, column matrix
● equality, of matrices
● equating elements of column matrices
H
● Head-to-Tail Rule, vector addition
I
● identity matrix
● identity matrix, matrix product
● identity, transpose
● identity, unique
● inner product
● inverse inverse
● inverse of matrix product
● inverse of matrix transpose
L
● length and direction, converting to (x,y)
● length, of 3D vectors
● length, of a vector
● length, of negated vector
● length, of vector aligned with axis
● length, of vector, formula
● length, vector
● length, vector, always positive or zero
M
file:///C|/InetPub/wwwroot/VectorLessons/tutorialIndex.html (3 of 7) [10/9/01 2:25:06 PM]
Vectors and Matrices Index
N
● negative column matrix
● normal, many meanings of
● normalizing a vector
O
● orientation, 2D vector formula
● orientation, of 2D vector
● orthogonal vector, creating
● orthogonal vectors, dot product
P
● parallelogram
● plane, defined by two vectors
● point
● point, represented as column matrix
● points, represented as column matrix
● points, represented in different frames
● projection, fast formulae
● projection, one vector onto another
● projection, vector, formula
● projection, vector, orthogonal component
● projection, vector, procedure
● pythagorean formula
R
● radians
● right-hand rule
● row matrix times matrix
● row matrix times matrix, definition
S
● scalar
● scalar multiplication, matrix
● scalar product
● scaling, of a vector
● scaling, properties
● slope
● slopes, of perpendicular lines
● solid geometry problems, and vectors
T
● terms review
● translation
● transpose
● transpose, of a column matrix
● triangle inequality
● triangle inequality, example
U
● unit normal
● unit normals, in 3D
● unit vector
● unit vector
● unit vector, as direction
● unit vector, orientation
V
● vector
● vector
● vector addition, associative property
● vector addition, commutative property
● vector addition, in three dimensions
● vector orientation, trouble with negative components
● vector projection, 3D example
● vector, represented with column matrix
● vectors, colinear
Z
● zero matrix
● zero matrix
● zero vector, addition of
ABCDEFGHIJKLMNOPQRSTUVWXYZ
No, they have the same dimensions, but corresponding elements are not equal.
Matrix Addition
If two matrices have the same number of rows and same number of columns, then the matrix sum can
be computed:
If A is an MxN matrix, and B is also an MxN matrix, then their sum is an MxN matrix
formed by adding corresponding elements of A and B
Of course, in most practical situations the elements of the matrices are real numbers with decimal
fractions, not the small integers often used in examples.
QUESTION 7:
What 3x2 matrix could be added to a second 3x2 matrix without changing that second matrix?
What 3x2 matrix could be added to a second 3x2 matrix without changing that second matrix?
Zero Matrix
A zero matrix is one which has all its elements zero. Here is a 3x3 zero matrix:
The name of a zero matrix is a bold-face zero: 0, although sometimes people forget to make it bold
face. Here is an interesting problem:
QUESTION 8:
A+B=B+A
A+0=0+A=A
0+0=0
These look the same as some rules for addition of real numbers. (Warning!! Not all rules for matrix
math look the same as for real number math.)
The first rule says that matrix addition is commutative. This is because ordinary addition is being done
on the corresponding elements of the two matrices, and ordinary (real) addition is commutative:
QUESTION 9:
QUESTION 10:
QUESTION 6:
More Practice
Compute each dot product in the following table. Check your answer in the "Result" column.
QUESTION 7:
Fill in the result column matrix with a reasonable guess. (Hint: look at the results in the table.)
Do you think that it is possible to form a product that looks like this:
1 x 2 2 x 1 = 1 x 1
It might look slightly odd to regard a scalar (a real number) as a "1 x 1" object, but doing that keeps
things consistent. Notice that this example looks like a dot product. In fact, it is. Knowing that, you
know how the product is formed:
QUESTION 5:
1 3
det -1 2 = 1*2 - 3*(-1) = 2+3 = 5
a b
det c d = a*d - b*c
Computing the determinant of larger matrices is more complicated, and rarely done. The determinant
is mostly used in discussing matrices, not in computing with them. The following property is often
useful:
QUESTION 14:
Compute the following determinant (just plug into the above formula):
1 2
det 1 2
1 2
det 1 2 = 1*2 - 2*(1) = 2 -2 = 0
Rank of a Matrix
The matrix has a zero determinant and is therefor singular. It has no inverse. If you look the matrix
you see that it has two identical rows (and two identical columns). In other words, the rows are not
independent. If one row is a multiple of another, then they are not independent, and the determinant is
zero. (Equivalently: If one col is a multiple of another, then they are not independent, and the
determinant is zero.)
The rank of a matrix is the maximum number of independent rows (or, the maximum number of
independent columns). A square matrix An×n is non-singular only if its rank is equal to n.
QUESTION 15:
1 2 0 3
1 -2 3 0
0 0 4 8
2 4 0 6
If two matrices contain the same numbers as elements, are the two matrices equal to each other?
No, to be equal, two matrices must have the same dimensions, and must have the same values in the
same positions.
Matrix Equality
For two matrices to be equal, they must have
Here are two matrices which are not equal even though they have the same elements.
QUESTION 6:
No. This is not quite obvious, but since 1 is unique you might suspect that I is unique.
I is Unique
It is easy to show that this is so. Suppose you had a matrix Z and that
(1) ZA = A
(2) BI = B
(3) ZI = I
(4) ZI = Z
(4) Z = I
QUESTION 5:
1 0 0 T
0 1 0
0 0 1
1 0 0 T 1 0 0
0 1 0 =
0 1 0
0 0 1 0 0 1
Transpose of I
For any dimension: IT = I.
IT = I
Another useful property is the following. Actually, this is really just an application of the definition of
I.
AIB = AB
II = I, or I2 = I
These are all obvious; you should not have to memorize anything here. But it does help to look them
over.
QUESTION 6:
2 4 6 1 2 3
0.5
0 -12 -8 =
0 -6 -4
4 0 4 2 0 2
Diagonal Matrix
The diagonal matrix (aI) is sometimes useful in computer graphics. Say for example that what you want
to compute is:
a ABx
where a is a scalar and x is a column vector. Sometimes it is convenient to think of this as:
(aI)ABx
Now every operation is matrix multiplication. (This sometimes has a practical advantage with graphcis
hardware).
QUESTION 7:
What is (2I)(0.5I)?
p = (1 2)T
Matrix Inverse
It was tedious to figure that out (and would be much worse if A were, say, 5 × 5). It would be nice to
have a better way. Say that
(1) q = Ap
for column vectors p and q and n×n matrix A . Is it possible to find a matrix Bn×n so that
(2) p = Bq
(3) q = A(Bq)
(4) q = (AB)q
If (4) is true, then (AB) = I. (Remember that I is unique). B, if it exists, is the inverse of A, written A-
1, and the following is true:
AA-1 = A-1A = I
QUESTION 10:
For any square matrix A, is there always going to be an inverse A-1 ? Hint: consider the zero matrix.
Non-singular
In fact, it is worse than that. There are very many n × n matrices that do not have an inverse. A matrix
that does have an inverse is called non-singular. A matrix that does not is called singular. If the
matrix A is non-singular, then:
AA-1 = A-1A = I
A A-1 = I
1 2 1 -2 1 0
0 1 0 1 = 0 1
Rarely is an inverse as easy to find as the above one. Now, say that
1 2 5
0 1 p= 2
QUESTION 11:
= A I A-1 = AA-1 = I
Notice that the order of the matrices has been reversed on the right of the "=" . Another sometimes
useful property is:
(A-1)T = (AT)-1
QUESTION 13:
1 3
-1 2
(If you have forgotten about determinants, or wish you had, don't worry. They won't be used much.)
10 0 20 -2 2 1 0 2 -2 2 2 -2 1 -1
20 40 10 1 1 = 10
2 4 1 1 1 = 10
2 6 = 20
1 3
0 20 10 2 -2 0 2 1 2 -2 4 0 2 0
Associative
Multiply the first two following matrices together. Click on the = to check your result. Then multiply the result with the
third matrix.
1 -1 -2 1 -1 0 -1 0
2 3 0 2 1 1 = ?? 1 1 = ??
?? ??
Now do the problem again, but this time start by multiplying the last two matrices.
1 -1 -2 1 -1 0 1 -1
2 3 0 2 1 1 = 2 3 ?? = ??
?? ??
The final answer is the same for both ways of doing the problem. This demonstates the fact that matrix multiplication is
associative:
(AB)C = A(BC)
Of course, the inner dimension of A and B must be the same, and the inner dimension of B and C must be the same.
Usually a product of three matrices is written ABC.
QUESTION 11:
Distributive Property
The distributive property deals with a matrix expression that contains both matrix multiplication and
matrix addition. Go through the following steps to demonstrate the property.
1. Add the
right two
matrices
together, 1 2 1 0 0 2
click = to + =
check -2 1 -2 1 -2 1
your
result,
below.
2.
Multiply
the first
matrix
1 2
times the
=
result.
-2 1
Click "="
to check
your
result.
3. Now,
work the
problem
again by
forming
1 2 1 0 1 2 0 2
the
+ =
product of
-2 1 -2 1 -2 1 -2 1
the left
matrix
and each
of the
others.
4. Finally,
add up the
+ =
two
products.
Both results are the same, demonstrating that matrix multiplication is distributive over matrix
addition:
A(B + C) = AB+AC
(X + Y)Z = XZ+YZ
For more practice, change the elements in the matrices of step 1 (only), and then work the problem
again. When you make changes, replace the contents of a cell with an integer (only) and click outside
of the cell to make the change.
QUESTION 12:
cos w 1 x 2
0 sin w 1 y
Say that you are forming the product A5×3 B3×2 = C5×2
What row and column are used to calculate the 3rd row 2nd column of C ?
QUESTION 5:
● c11 ?
● c32 ?
Although most of our examples have used integers, don't forget that matrix elements can be real
numbers or variables.
Conformant Matrices:
if AM×K BK×N = C, then C = CM×N
Not Commutative:
AB =/= BA, except rarely.
Associative:
A(BC) = (AB)C = ABC
Scalar factor:
a(AB) = (aA)B = aAB = A(aB)
Distributive:
A( B + C) = AB + AC
Distributive:
(A + B)C = AC + BC
Multiplication by zero:
0A = 0, for the zero matrix 0
You have reached the end of this chapter. The next chapter will discuss further properties of matrix-
matrix multiplication.
NO! Even when both products can be formed they are rarely equal.
Not Commutative
For example, calculate both of the following products (you might wish to use paper and pencil):
Answer
Answer
The results show that in general for matrices A and B, AB =/= BA.
QUESTION 8:
More Practice
It would be good at this point to practice matrix multipliction. The goal is to interalize the idea so that
it becomes one of your active concepts, not a faintly recalled notion you have to look up each time.
In the following, mentally (or on paper) multiply the two matrices. Click on the "=" button to check
your answer. Change elements in A and B and work the problem again. To change an element,
replace the contents of a cell with an integer (only) and then click outside of the cell.
A B = C
1 2 1 0
=
-2 1 -2 1
1 0 1 2 1 0 1 2
0 1 3 4 = 0 1 3 4 =
QUESTION 9:
Scalar Factor
Recall that xA means that every element of A is multiplied by x. Here is a demonstration of the rule:
Often a matrix-matrix multiplication can be simpified by factoring one of the matrices. See the question.
QUESTION 10:
10 0 20 -2 2
20 40 10 1 1
0 20 10 2 -2
QUESTION 10:
3 x 4 1 x 3 = ?
1 x M M x C 1 x C
A 1xC matrix is a row matrix of "C" number of columns. For each row in the following table, decide
if the product can be formed and what the dimensions of the result will be.
3x3 3x1 ?
1x2 2x2 ?
1x2 2x3 ?
4x4 3x1 ?
1x5 5x3 ?
QUESTION 11:
A-1 A p = A-1 q
1 -2 1 2 1 -2 5
0 1 0 1 p = 0 1 2
1 -2 5
Ip= 0 1 2
1 -2 5 1
p= 0 1 2 = 2
Unique A-1
This is (hopefully) the same answer you got for p by trial and error a few pages ago. If A is non-
singular (has an inverse) and Ap = q, then p = A-1q.
The inverse of a non-singular square matrix is unique. One way to see this is that there is only one
column matrix p that is the solution to Ap = q, so there must be only one A-1.
It might look like computing A-1 is a useful thing to do. In fact, A-1 is more useful in discussions
about matrices and transformations than it is in actual practice. Almost never do you really want to
compute a matrix inverse.
For example, say that a column matrix p represents a point in a computer graphic world. The
viewpoint changes, and the column matrix is transformed to q = Ap. If you want to talk about
reversing the transformation, you talk about A-1q. But almost always there is an easier way to reverse
the transformation than to compute the inverse.
QUESTION 12:
Here is another example, with the result not yet quite complete:
QUESTION 8:
Mentally flip (transpose) the column matrix and compute the result.
Answer
Answer
Answer
QUESTION 9:
Is Ax equal to xA ?
No. If one product can be formed, then often the second one has incompatible dimensions. Sometimes
both products can be formed, but even then the numbers will usually be different.
More Practice
You might enjoy testing your skills on the following:
Answer
Answer
Answer
QUESTION 14:
Had enough?
Yes.
Steps in Multiplication
By the definitions on the previous page, multiplication always involves dot products of rows on the
left with columns on the right. So, To do any of these calculations:
❍ "Cancel" the inner dimensions to find the dimensions of the result, eg., 1xC.
QUESTION 13:
Is Ax equal to xA ?
1 2 0 3
1 -2 3 0
0 0 4 8
2 4 0 6
● IA = AI = A
● I is unique.
● IT = I
● AIB = AB II = I
● AA-1 = A-1A = I
● Singular and non-singular matrices.
● Uniqueness of matrix inverse.
● (AB)-1 = B-1 A-1
● (A-1)T = (AT)-1
● Determinant of a singular matrix.
Matrix Subtraction
If A and B have the same number of rows and columns, then A - B is defined as A + (-B). Usually
you think of this as:
Notice in particular the elements in the first row of the answer. The way the result was calculated for
the elements in row 1 column 2 is sometimes confusion.
QUESTION 13:
Transpose
The transpose of a matrix is a new matrix who's rows are the columns of the original (which makes its
columns the rows of the original). Here is a matrix and its transpose:
The superscript "T" means "transpose". Another way to look at the transpose is that the element at
row r column c if the original is placed at row c column r of the transpose. We will usually work with
square matrices, and it is usually square matrices that will be transposed. However, non-square
matrices can be transposed, as well:
QUESTION 14:
Careful Definitions
You may be uneasy with mathematical operations being defined in this casual fashion. Here are some
more accurate definitions:
QUESTION 12:
QUESTION 15:
(2I)(0.5I) = I
Product Yields I
It is clear that (2I)(0.5I) = 2 (0.5)I = 1I = I. But, just for practice, mentally multiply out these matrices
the long way:
2 0 0 1/2 0 0
0 2 0 0 1/2 0
0 0 2 0 0 1/2
The rows from the first matrix "match" the columns of the second so that the dot product is 1 only for
the major diagonal. All other dot products are 0. The resulting matrix is I.
QUESTION 8:
Say that ax = b for real numbers a and b and real variable x. Solve for x.
Square matrices are used (in computer graphics) to represent geometric transformations.
Sometimes you write A = [aij] to say that the elements of matrix A are named aij.
QUESTION 5:
(Thought Question:) If two matrices contain the same numbers as elements, are the two matrices
equal to each other?
Each element in the result is the negative of the original, as seen below.
Negative of a Matrix
The negation of a matrix is formed by negating each element of the matrix:
-A = -1 · A
QUESTION 12:
Look at the above fact. Can you think of a way to define matrix subtraction?
To multiply a matrix by a scalar, multiply each element of the matrix by the scalar.
QUESTION 11:
Show the result if the scalar a in the above is the value -1.
Multiplication Practice
You are surely eager to perform a matrix-matrix product! In the following diagram, mentally calculate
the dot product that belongs in each cell. Then move the mouse over it to see the correct value.
In order for the above to work you must use a recent web browser (such as Netscape Navigator 4.0)
and have JavaScript enabled. If it doesn't work, work out the answer with paper and pencil.
QUESTION 6:
The transpose of a row matrix is a column matrix. And the transpose of a column matrix is a row
matrix.
Rule Summary
Here are some rules that cover what has been discussed. You should check that they seem reasonable,
rather than memorize them. For each rule the matrices have the same number of rows and columns.
a0 = 0 (-1)A = -A A - A= 0
(AT)T = A 0T = 0
In the above, a and b are scalars (real numbers). A and B are matrices, and 0 is the zero matrix of
appropriate dimension.
QUESTION 16:
Solve for p
The value (a-1) is the inverse of a, and all non-zero real numbers have an inverse. It would be nice to
have a similar idea for square matrices.
Say that
Ap = q
for column vectors p and q and n×n matrix A . In computer graphics terms, the point represented by
the column matrix p has been transformed into the point represented by q.
If all know are A and q, is it possible to figure out what p is? For example, say that you know that
1 2 5
0 1 p= 2
Try to figure out p from the following. Keep changing the elements of p until the result is q.
A p = q
1 2 1
=
0 1 1
QUESTION 9:
Most spreadsheet programs and medium priced electronic calculators include matrix math functions.
You might wish to investigate whatever you have. But for these exercises, try to do the work "in your
head" in order to internalize the process.
"It is important to practice the ... procedure for multiplying matrices until it becomes automatic. Also,
you should be able to pick out immediately the row of A and the column of B that combine to give a
particular entry in AB."1
1. Ben Noble and James Daniel, Applied Linear Algebra, 3rd., Prentice-Hall, 1988.
QUESTION 7:
Yes.
● Definition of a matrix.
● Matrix elements.
● Matrix dimensions.
● Names for matrices and their elements.
● When two matrices are equal.
● Matrix addition.
● The Zero matrix.
● Rules for adding matrices.
● Scalar multiplication of a matrix.
● Negation of a matrix.
● Matrix Subtraction.
● Matrix Transpose
The next chapter will discuss more things that can be done with matrices.