Math for CG (old version - geometric spaces walkthrough)

advertisement
Linear Algebra Review for
Computer Graphics
Matt Boggus
CSE 3451/5541
Outline – Linear Algebra topics
• Scalars
• Vector Space
– Scalars and vectors
• Affine Space
– Scalars, vectors, and points
• Euclidean Space
– Scalars, vectors, points
– Distance metric
• Projections
• Matrix representations and operations
Scalars
• Scalar – a number
– Ex: the scale, weight, or magnitude of something
• Two Fundamental Operations
– Addition and multiplication
 ,   S ,     S ,     S
     
     
            
            
               
Commutative
Associative
Distributive
Scalars
• Two Special Scalars
– Additive identity: 0, multiplicative identity: 1
  0  0   
 1  1    
– Additive inverse

      0
– Multiplicative inverse
 1
   1  1
2D scalar field
2D array of scalar values
In C#, the data structure
might look something like
this:
float [,] temps;
temps = new float[50,50];
// (allocate after declaring)
http://upload.wikimedia.org/wikipedia/commons/a/a8/Scalar_field.png
Vector space
• Two Entities: Scalars and Vectors
• Vectors
– Directed line segments
– n-tuples of scalars
– Two operations
• vector-vector addition
• scalar-vector multiplication
• Zero Vector
v0v
v   v   0
Directed line segments
Vector space
• In vector space, two vectors are equal if they are
represented with the same n-tuple
– Ex:
(1,2,3) = (1,2,3)
(1,2,3) ≠ (3,2,1)
• A vector, by itself, does not have a starting position
– Visually you can think of a vector starting at (0,0,0)
Vector space operations
• Vectors = n-tuples v  v0 , v1 , , vn 1 
– Vector-vector addition
u  v  u0 , u1 ,  , u n 1   v0 , v1 ,  , vn 1 
 u0  v0 , u1  v1 ,  , u n 1  vn 1 
– Scalar-vector multiplication
v  v0 , v1 ,  , vn 1 
– Vector decomposition




u   0u0  1u1     n 1u n 1
Vector space operations
• Scalar-Vector Multiplication
u and v: vectors, α and β: scalars
 u  v   u  v
   u  u  u
Scalar-vector multi.
• Vector-Vector Addition
– Visualize using head-to-tail axiom
Head-to-tail axiom
Vector space limitations
• Vector space has no geometric concept
– Vectors indicate magnitude and
direction, not position
• Coordinate System
– Origin: a particular reference point
Basis
vectors
located
at the
origin
Identical vectors
Arbitrary
placement
of basis
vectors
Coordinate system
Boardwork examples: 1D, 2D, 3D coordinate axes
Unity uses left-handed coordinate system with
+x being right and +y being up
Affine Spaces
• Scalars, vectors, and points
• A point is represented as an n-tuple
• Operations [P and Q are points, v is a vector]
– Point-point subtraction operation

v  P Q
•
Vector-point addition operation

P  v Q
Head-to-tail axiom for points
P  Q  Q  R  P  R
 

• Frame: a Point P0 and a Set of Vectors v0 , v1 ,  , vn 1
– All vectors and points in the space are defined relative to these
Vector
v   0 v0  1v1     n 1vn 1
Point
P  P0   0 v0  1v1     n 1vn 1
Euclidean Spaces
• Affine space does not include an operation or metric
for distance between points
• Create a new operation: Inner (dot) Product
– Input: two vectors
Output: scalar
– α, β : scalars
u, v, w : vectors
– Properties we want: u  v  v  u
u  v   w  u  w  v  w
v  v  0 if v  0
00  0
For orthogonal vectors u  v  0
Euclidean Spaces – dot product
• If we can multiply two n-tuples, this implies
– Magnitude (length) of a vector
v 
vv
– Distance between two points
P Q 
– Measure of the angle between two vectors
• cosθ = 0  orthogonal
• cosθ = 1  parallel
P  Q   P  Q 
u  v  u v cos 
• Computation of dot product
n 1
u  v   ui  vi  u0  v0  u1  v1  ...  u n 1  vn 1
i 0
Projections
• We can determine if two points are “close” to each
other, what about vectors?
• How much of w is in the same direction as v?
• Given vectors v and w, decompose w into two parts,
one parallel to v and one orthogonal to v
w  v  u
w  v  v  v  u  v  v  v
wv
 
vv
wv
 u  w  v  w 
v
vv
Projection of one
vector onto another
Matrices
•
•
•
•
•
Definitions
Matrix Operations
Row and Column Matrices
Change of Representation
Relating matrices and vectors
What is a Matrix?
• A matrix is a set of elements, organized into
rows and columns
rows
columns
a b 
c d 


Definitions
• n x m Array of Scalars (n Rows and m Columns)
– n: row dimension of a matrix, m: column dimension
– m = n  square matrix of dimension n
– Element aij , i  0,  , n  1, j  0,  , m  1
 
 
A  aij
– Transpose: interchanging the rows and columns of a matrix
 
AT  a ji
 b0 
• Column Matrices and Row Matrices
b 
– Column matrix (n x 1 matrix): b  bi    1 
  
– Row matrix (1 x n matrix):


T
bn 1 
b  b0 b1 ... bn 1 
Matrix Operations
• Scalar-Matrix Multiplication A  aij 
– Multiply every element by the scalar
C  A  B  aij  bij 
• Matrix-Matrix Addition
– Add elements with same index
• Matrix-Matrix Multiplication
– A: n x l matrix, B: l x m  C: n x m matrix
 
C  AB  cij
l 1
cij   aik bkj
k 0
cij = the sum of multiplying
elements in row i of matrix a
times elements in column j of
matrix b
Matrix Operation Examples
a b   e
c d    g

 
f  a  e b  f 


h  c  g d  h 
a b   e
c d    g

 
f  a  e b  f 


h  c  g d  h 
a b   e
c d   g


f  ae  bg


h  ce  dg
af  bh
cf  dh 
Matrix Operations
 A    A
• Properties of Scalar-Matrix Multiplication
A  A
• Properties of Matrix-Matrix Addition
– Commutative:
– Associative:
AB BA
A  B  C  A  B  C
• Properties of Matrix-Matrix Multiplication
ABC  AB C
AB  BA
• Identity Matrix I (Square Matrix)
1
0

0

0
0
1
0
0
0
0
1
0
0
0
0

1
1 if i  j
I  aij , aij  
0 otherwise
 
AI  A
IB  B
Matrix Multiplication Order
• Is AB = BA? Maybe, but maybe not!
a b   e
c d   g


f  ae  bg ...


h   ...
...
e
g

f  a b  ea  fc ...




h   c d   ...
...
• In general, matrix multiplication is NOT
commutative!
• The order of matrix multiplications is
important!
Row and Column Matrices + points
• Column Matrix
– Row matrix
• Concatenations
– Associative
• By Row Matrix
 x
p   y 
 z 
pT  x
By convention
we will use
column matrices
for points
y
z
p  Ap
p  ABCp
AB T
 BT A T
pT  pT CT BT AT
Vector Operations
• Vector: 1 x N matrix
• Interpretation: a line
in N dimensional
space
• Dot Product and
Magnitude
operations
a 
  
v  b 
 c 
y
v
x
Vectors: Dot Product
d 
a  b  abT  a b c e   ad  be  cf
 f 
a  aa T  aa  bb  cc
2
a  b  a b cos( )
Think of the dot
product as a matrix
multiplication
The magnitude is the dot
product of a vector with
itself
If a and b are both length
one, the angle between
them is the cos-1 of their
dot product
Inverse of a Matrix
• Identity matrix:
AI = A
• Some matrices have an
inverse, such that:
AA-1 = I
1 0  1


A  0 1  1
0 0 1 
1 0 0


I  0 1 0 
0 0 1
1 0 1


1
A  0 1 1
0 0 1
Inverse of a Matrix
• Some matrices do not have an inverse
0 0 0 


A  0 1 0 
0 0 1
AA-100 =
a b

1
A  d e
 g h
0*a+0*d+0*g=0≠1
c

f
i 
Inverse of Matrix Concatenation
• Inversion of concatenations
(ABC)-1 = C-1B-1A-1
A*B*C*X=I
A * B * C * C-1 = A * B
A * B * B-1 = A
A * A-1 = I
Order is important, so X = C-1B-1A-1
Summary
• Primitives: scalars, vectors, points
• Operations: addition and multiplication
• Matrix representation and operations
Download