CPCS 391
Computer Graphics 1
Instructor: Dr. Sahar Shabanah Computer Graphics Math Review
Scalars
• Scalar Field
– Ex) Ordinary real numbers and operations on them
• Two Fundamental Operations
– Addition and Multiplication
– Commutative
– Associative
– Distributive
S S
S
, , ,
a + b = b + a a × b = b × a
a + ( b + g ) = ( a + b ) + g
a × ( b × g ) = ( a × b ) × g
a × ( b + g ) = ( a × b ) + ( a × g )
Scalars
• Two Special Scalars
– Additive identity: 0,
– multiplicative identity: 1 – Additive inverse and – Multiplicative inverse
a + 0 = 0 + a = a
1
a + - ( ) a = 0
a × 1 = 1 × a = a
a × a
-1= 1
Vectors
• A vector is a directed line segment:
– starts at initial point (A) and – ends at terminal point (B)
• Components of v
• In general:
– v = n-tuples
• Special Vectors:
– Zero Vector
– Negative Vector
4
v = AB
00
u u
u u
v v vn
v 1, 2,,
v = (x2 - x1,y2 - y1) =
(
v1,v2)
A(X1,Y1)B(X2,Y2)
v
• Scalar-Vector Multiplication
u and v: vectors, α and β: scalars
Vectors Operations
a (
u + v)
=a
u +a
va
+b
( )
u =a
u +b
u v v v
n
v
1,
2, ,
Vectors Operations
• Magnitude (length)
• Vector-Vector Addition
– Head-to-tail axiom:
– u+v=(u tial, v head)
u u u v u u
nv v u v
nv
nv
nv u
, ,
,
, ,
, ,
, ,
2 2
1 1
2 1 2
1
v = v
12+ v
22+ .. + v
n2
Vectors Operations
• Vector-Vector Difference
u - v = ( u
1, u
2, … , u
n) - ( v
1, v
2,… , v
n)
= ( u
1- v
1, u
2- v
2,… , u
n- v
n)
V
U
U-V
Vectors Operations
• dot Product:
– combine two vectors to form a real number
– measure of the angle between two vectors, to what degree those two vectors are aligned
» cosθ = 1 parallel
» cosθ = 0 orthogonal
n nv u v
u v
u v
u
or v
u v
u
...
.
, cos .
2 2 1
1
v u
v cos u.
• The cross product of vectors u and v is a vector uxv which is perpendicular to u and v
• The magnitude of uxv is proportional to the cosine of the angle between u and v
• The direction of uxv follows the right hand rule
Vectors: Cross Product
u ´ v = (u
2v
3- u
3v
2, u
3v
1- u
1v
3, u
1v
2- u
2v
1) or
u ´ v = u v sin q
Affine Space
• In 3D Space, a unit Vector, e3 , is Orthogonal to Given Two Nonparallel Vectors, e1 and e2
• Definition
• Consistent Orientation
– Ex) x-axis x y-axis = z-axis
0 2
3 1
3 e e e e
1 2 2
1
3 1 1
3
2 3 3
2
2 1
3
e e
e
1,
2,
3 , 2
1,
2,
3
1
where e e
Affine Spaces
Coordinate System
Origin: a particular reference point
Arbitrary placement
of basis vectors Basis
vectors located at the origin
What is a Matrix?
• A matrix is a set of elements, organized into rows and columns
rows
columns
d c
b
a
Definitions
• dimension of a matrix
– n x m array of scalars (n Rows and m Columns)
• square matrix
– m = n square matrix of dimension n
• Element
• Transpose:
– interchanging the rows and columns of a matrix
• Column and Row Matrices:
– Column matrix (n x 1 matrix):
– Row matrix (1 x n matrix):
a
ij, i 1 , , n , j 1 , , m
aij
A
jiT a
A
n i
b b b
b
2 1
b
Basic Operations
• Addition
• Subtraction
• Multiplication
h d
g c
f b
e a
h g
f e
d c
b a
h d
g c
f b
e a
h g
f e
d c
b a
dh cf
dg ce
bh af
bg ae
h g
f e
d c
b a
Just add elements
Just subtract elements
Multiply each row by each column
Matrix Operations
• Scalar-Matrix Multiplication
• Matrix-Matrix Addition
• Matrix-Matrix Multiplication
– A: n x l matrix, – B: l x m
– C: n x m matrix
a
ij A
a
ij b
ij
A B C
l
k
kj ik ij
ij
b a c
c
1
AB
C
Properties of Matrix Operations
• Scalar-Matrix Multiplication
• Matrix-Matrix Addition – Commutative:
– Associative:
• Identity Matrix I (Square Matrix)
A A
A A
A B
B
A
B C
A B
CA
0 otherwise
if 1
, i j
a aij ij
I IB B
A AI
Matrix Multiplication:
• Associative:
• Is AB = BA? Maybe, but maybe not!
• multiplication is NOT commutative!
Properties of Matrix Operations
...
...
...
bg ae
h g
f e
d c
b
a
...
...
...
fc ea
d c
b a
h g
f e
A(BC)=(AB)C
Row and Column Matrices
• Column Matrix
– p
T: row matrix
• Concatenations
– Associative
• By Row Matrix
z y x p
ABCp p
Ap p
T T
T T
T
T T T
A B
C p
p
A B
AB
X Y Z
T
p
Inverse of a Matrix
• Identity matrix:
AI = A
• Some matrices have an inverse:
AA
-1= I
• Inversion is tricky:
(ABC)
-1= C
-1B
-1A
-1Derived from non-commutativity property
1 0
0
0 1
0
0 0
1 I
• Used for inversion
• If det(A) = 0, then A has no inverse
Determinant of a Matrix
d c
b
A a det( A ) ad bc
a c
b d
bc A 1 ad 1
Sum from left to right
Subtract from right to left Note: N! terms
Determinant of a Matrix
ceg bdi
afh cdh
bfg aei
i h
g
f e
d
c b
a
i h
g
f e
d
c b
a
i h
g
f e
d
c b
a
i h
g
f e
d
c b
a