Lecture 10
Lecture 10
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.
110
© Copyright Virtual University of Pakistan
Computer Graphics (CS602)
The upper left corner of the matrix is row 1 column 1. In the above matrix the
element at row 1 column 1 is the value 1. The element at row 2 columns 3 is the
value 4.6.
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.
111
© Copyright Virtual University of Pakistan
Computer Graphics (CS602)
A column matrix is also called column vector and call a row matrix a row
vector.
Question: What are square matrices used for?
Answer: 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: (Thought Question:) If two matrices contain the same numbers as
elements, are the two matrices equal to each other?
Answer: No, to be equal, two matrices must have the same dimensions, and
must have the same values in the same positions.
Here are two matrices which are not equal even though they have the same
elements.
112
© Copyright Virtual University of Pakistan
Computer Graphics (CS602)
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: What 3x2 matrix could be added to a second 3x2 matrix without
changing that second matrix?
Answer: The 3x2 matrix that has all its elements zero.
113
© Copyright Virtual University of Pakistan
Computer Graphics (CS602)
You should be happy with the following rules of matrix addition. In each rule, the
matrices are assumed to all have the same dimensions.
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:
114
© Copyright Virtual University of Pakistan
Computer Graphics (CS602)
Question: Show the result if the scalar a in the above is the value -1.
Answer: Each element in the result is the negative of the original, as seen below.
10.1.11 Negative of a Matrix
The negation of a matrix is formed by negating each element of the matrix:
-A = -1A
So, for example:
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.
115
© Copyright Virtual University of Pakistan
Computer Graphics (CS602)
10.1.13 Transpose
The transpose of a matrix is a new matrix whose 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:
Answer:
116
© Copyright Virtual University of Pakistan
Computer Graphics (CS602)
Answer:
The transpose of a row matrix is a column matrix. And the transpose of a column
matrix is a row matrix.
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: If A = B and B = C, then does A = C?
Answer: Yes
117
© Copyright Virtual University of Pakistan
Computer Graphics (CS602)
10.2 Vectors
Another important mathematical concept used in graphics is the Vector. If P1 =
(x1, y1, z1) is the starting point and P2 = (x2, y2, z2) is the ending point, then the
vector V = (x2 – x1, y2 – y1, z2 – z1)
and if P2 = (x2, y2, z2) is the starting point and P1 = (x1, y1, z1) is the ending
point, then the vector V = (x1 – x2, y1 – y2, z1 – z2)
118
© Copyright Virtual University of Pakistan
Computer Graphics (CS602)
119
© Copyright Virtual University of Pakistan
Computer Graphics (CS602)
V = (1, 2, 3)
|V| = sqrt( 12 + 22 + 32) = sqrt(14) + 3.74
Vnorm = V / |V| = (1, 2, 3) / 3.74 =
(1 / 3.74, 2 / 3.74, 3 / 3.74) = (.27, .53, .80)
Note that the last calculation doesn’t come out to exactly 1. This is because of
the error introduced by using only 2 decimal places in the calculations above.
120
© Copyright Virtual University of Pakistan
Computer Graphics (CS602)
The Dot Product computation can be simplified when it is known that the vectors
are unit vectors
V1 . V2 = cos(θ)
because |V1| and |V2| are both 1
121
© Copyright Virtual University of Pakistan
Computer Graphics (CS602)
Note that if you are big into linear algebra there is also a way to do the cross
product calculation using matrices and determinants
Again, just as with the dot product, there is a more graphical definition:
V1 x V2 = u |V1| |V2| sin (θ)
where θ is the angle between the 2 vectors and θ is in the range 0 ≤ θ ≤ Π and u
is the unit vector that is perpendicular to both vectors
Why u?
|V1| |V2| sin(θ) produces a scalar and the result needs to be a vector.
122
© Copyright Virtual University of Pakistan
Computer Graphics (CS602)
123
© Copyright Virtual University of Pakistan