Anda di halaman 1dari 20

Matrix Math

Anthony Steed 1999

1
Overview
To revise
Vectors
Matrices
New stuff
Homogenous co-ordinates
3D transformations as matrices

2
Vectors and Matrices
Matrix is an array of numbers with
dimensions M (rows) by N (columns)
3 by 6 matrix
element 2,3 3 0 0 2 1 2
1 1 3 4 1 1
is (3) 5 2 0 0 0 1

Vector can be considered a 1 x M matrix



v x y z
3
Types of Matrix
Identity matrices - I Symmetric

1 0 0 0 a b c
0 b d e
1
0
0 1 0 0 c e f
1 0 0 1 0
0 0 0 1

Diagonal matrices
Diagonal are (of course)
1 0 0 0 symmetric
0 2 0 0 Identity matrices are
0 0 1 0
0 (of course) diagonal
0 0 4

4
Anthony
AnthonySteed:
Steed:
EQ
EQneeds
needsfixing
fixing

Operation on Matrices
Addition
Done elementwise
c d r s c r d s

a b p q a p b q

Transpose
Flip (M by N becomes N by M)
T
1 4 9 1 5 6
5 2 8 4 2 7
6 7 3 9 7 3

5
Operations on Matrices
Multiplication
Only possible to multiply of dimensions
x1 by y1 and x2 by y2 iff y1 = x2
resulting matrix is x1 by y2
e.g. Matrix A is 2 by 3 and Matrix by 3 by 4
resulting matrix is 2 by 4
Just because A x B is possible doesnt mean
B x A is possible!

6
Matrix Multiplication Order
*
* *
* * * * *

*
A is n by k , B is k by m *
*

C = A x B defined by
. *
. . *
* * * * *
*


. *
k . *

cij ailblj
. *

BxA notl necessarily . *


. . .
1 . . . . .
*
. *
equal to AxB
* * * * *
. *
. *
. *

7
Example Multiplications

2 1
2 3 1 1 1 __ __
1 0 1
0 1 __ __

2 2 3 0 0 1 __ __ __
3 1 0 1 0 0 __ __ __
1 1 1 0 1 0
__ __ __
8
Inverse
If A x B = I and B x A = I then
A = B-1 and B = A-1

9
Anthony
AnthonySteed:
Steed:
EQ
EQneeds
needsfixing
fixing

3D Transforms
In 3-space vectors are transformed by
3 by 3 matrices
a b c
x y z d e f xa yd zg xb ye zf xc yf zi
g h i

Example?

10
Scale
Scale uses a diagonal matrix
a 0 0
x y z 0 b 0 xa yb zc
0 0 c
Scale by 2 along x and -2 along z
2 0 0
3 4 5 0 1 0 6 4 10
0 0 2
11
Rotation
Rotation about z axis
Y
cos( ) sin( ) 0 cos x - sin y sin x cos y

- sin( ) cos( ) 0
x y
0 0 1
X
Note z values remain the same whilst x and y change

12
Rotation X, Y and Scale
About X Scale (should look
1 0 0 familiar)
0 cos( ) - sin( )

0 sin( ) cos( ) a 0 0
0 b 0
0 0 c
About Y
cos( ) 0 - sin( )
0 1 0
sin( ) 0 cos( )

13
Homogenous Points
Add 1D, but constrain that to be equal to 1
(x,y,z,1)
Homogeneity means that any point in 3-
space can be represented by an infinite
variety of homogenous 4D points
(2 3 4 1) = (4 6 8 2) = (3 4.5 6 1.5)
Why?
4D allows as to include 3D translation in matrix
form

14
Homogenous Vectors
Vectors != Points
Remember points can not be added
If A and B are points A-B is a vector
Vectors have form (x y z 0)
Addition makes sense

15
Translation in Homogenous Form

1 0 0 0
0 1 0 0 x a y b z c 1
x y z 1 0 0 1 0
a b c 1

Note that the homogenous component


is preserved (* * * 1), and aside from
the translation the matrix is I

16
Putting it Together

R1 R2 R3 0
R4 R5 R6 0
R7 R8 R9 0
T1 T2 T3 1

R is rotation and scale components
T is translation component

17
Order Matters
Composition order of transforms
matters
Remember that basic vectors change so
direction of translations changed
1 0 0 0 1 0 0 0 1 0 0 0
1 0 0 0 X Z Y 1 0 1
0 X 2 Z 3 Y 4 1
X Y Z 1 00 0
1 0 0 0
1
0
0
1 0 0 0
0
1 0
0 0 0 1 2 3 4 1 2 3 4 1

1 0 0 0 1 0 0 0 1 0 0 0
0 0 1 0 X 2 Y 4 Z 4 1 0 0
1 0 X 2 Z 4 Y 4 1
X Y Z 1 00 1
0
0
1 0 0
0
1 0 0 0 1 1 0
2 3 4 1 0 0 0 1 0 0 0 1

18
Exercises
Show that rotation by/2 about X and then /2 about
Y is equivalent to /2 about Y then /2 about X
Calculate the following matrix /2 about X then /2
about Y then /2 about Z (remember then means
multiply on the right). What is a simpler form of this
matrix?
Compose the following matrix translate 2 along X,
rotate /2 about Y, translate -2 along X. Draw a
figure with a few points (you will only need 2D) and
then its translation under this transformation.

19
Summary
Rotation, Scale, Translation
Composition of transforms
The homogenous form

20

Anda mungkin juga menyukai