CS-321 Lecture

Math Review

Coordinate systems



2-D, 3-D
Vectors
Matrices

Matrix operations
1
Math Review



Cornerstone of graphics
Basis for most algorithms
Systematic notation



Simplifying communication
Organizing ideas
Compact representation
CS-321
Dr. Mark L. Hornick
2
2-D Coordinate Systems
y
P
0
Rectangular or
Cartesian
0
x
y
CS-321
Dr. Mark L. Hornick
x
P
3
Points and Vectors
y
A point at (x,y) can be represented by
vector P from the origin (0,0).
P
0
y
In general, a vector represents the
difference (directed distance)
between two points.
x
V  P2  P1
V
P2
P1
0
x

 x2
 x1 , y2  y1 
 Vx , V y
CS-321
Dr. Mark L. Hornick

4
2-D Vector Representations
V
Vy
Vx
Cartesian components
V  Vx ,Vy 
Magnitude and direction angle
|V|
V 
a
Vx
a  tan
CS-321
Dr. Mark L. Hornick
2
1
 Vy
2
 Vy 


V
x 

5
2-D Vector Operations
Addition

V1  V2  V1x  V2x ,V1y  V2 y

V1+V2
-V2
Subtraction

V2
V1
V1  V2  V1x  V2x ,V1y  V2 y

CS-321
Dr. Mark L. Hornick
V1-V2
V1
V2
6
2-D Vector Operations
Scalar
multiply
aV   aVx , aVy 
V
Vy
Vx
aV
aVy
aVx
CS-321
Dr. Mark L. Hornick
7
2-D Unit Vector
For any vector V,
V can also be
written as av
V   avx , av y 
V
Vx
a  V V  V
2
x
Vy
2
y
vx2  v y2  1
CS-321
Dr. Mark L. Hornick
8
Direction cosines
Vy
Vy
Vx
cos a 
, cos  
V
V
β
V
α
Vx
cos a  cos   1
2
2
CS-321
Dr. Mark L. Hornick
9
3-D Coordinate Systems
In a Right-handed
coordinate
system, the z axis
defined by the
vector cross
product of the x
and y axes.
y
P
z
CS-321
Dr. Mark L. Hornick
x
10
3-D Vector Operations

Addition
V1  V2  V1x  V2x ,V1y  V2 y ,V1z  V2z
Scalar
multiply
aV   aVx , aVy , aVz 
CS-321
Dr. Mark L. Hornick
11

3-D Vector Representations
V  Vx ,Vy ,Vz 
Cartesian components
Magnitude and direction cosines
V  Vx  Vy  Vz
2
z
V
γ
β
x
α
y
2
2
Vy
Vx
Vz
cos a 
, cos  
, cos  
V
V
V
cos a  cos   cos   1
2
CS-321
Dr. Mark L. Hornick
2
2
12
3-D Vector Operations
Inner (dot)
product
V1
θ
V2

V1  V2  V1x V2x  V1y V2 y  V1z V2z

 V1  V2 cos
Portion of V 2 in V1 direction
Projections
 V 2 cos θ 
CS-321
Dr. Mark L. Hornick
V1  V 2
V1
13
3-D Vector Cross Product
 V1y  V2z  V1z  V2 y , 


V1  V2   V1z  V2 x  V1x V2 z , 


V

V

V

V
1
2
1
2x 
x
y
y

“Right-hand rule”
V1 x V2
V2
θ
V1
CS-321
Dr. Mark L. Hornick
ux
uy
uz
 V1x
V1y
V1z
V2 x
V2 y
V2z
14
Matrices
Rectangular
matrix
(m x n)
(rows x cols)
Row vector
Column vector
 a11 a12
a
a
21
22

A


 am1 am 2
R   a1 a2
 a1 


C   a2 
 a3 
CS-321
Dr. Mark L. Hornick
a1n 

a2 n 


amn 
a3 
15
Scalar Matrix Multiplication
u v w 
M

x y z 
 au av aw
aM  

 ax ay az 
CS-321
Dr. Mark L. Hornick
16
Matrix Addition
a b
M
d e
c

f
u v w 
N

x y z 
 a  u b  v c  w
MN  

d  x e  y f  z 
Matrices must have same dimensions
CS-321
Dr. Mark L. Hornick
17
Matrix Transpose
u v w 
M

x y z 
u x


T
M   v y
 w z 
CS-321
Dr. Mark L. Hornick
18
Matrix Multiplication
 a11 a12
a
a22
21

A


 am1 am 2
a1n 
 b11 b12
b

b
a2 n 
21
22

B




amn 
bp1 bp 2
C  AB  cij 
b1q 

b2 q 


bpq 
n
cij   aik bkj
k 1
Matrices must be conformable (n=p)
CS-321
Dr. Mark L. Hornick
19
Matrix Multiplication Example
A
B
1
2
3
4
5
6
C
2
1
3
4
5
7
=
23
30
53
66
1 2  2  3  3  5  2  6  15  23
C row = A row, C column = B column
CS-321
Dr. Mark L. Hornick
20
Identity Matrix and Inverse
1 0
0 1
I


0 0
1
0
0 


1
Ax  b
1
xA b
1
AA  A A  I
Inverse computed by Gaussian elimination, determinants,
or other methods; used directly or indirectly to solve sets
of linearCS-321
equations
21
Dr. Mark L. Hornick
Determinants
1
A-1 =
adj(A)
det(A)
CS-321
Dr. Mark L. Hornick
22
Determinants

Only on square matrices

For an upper triangular matrix
n

A   a kk
k 1

Gaussian elimination is the best method



Swapping two rows changes the sign of A
Multiplying a row by s, multiplies A by s
Adding row multiples has no effect
CS-321
Dr. Mark L. Hornick
23