Matrices and Vectors for Computer Graphics

advertisement
MATRICES AND VECTORS FOR
COMPUTER GRAPHICS
PART 1
Cartesian Coordinates
I’m assuming everyone knows what this is:
(1,2)
(0,0)
Vectors and Points
 A vector is a direction
p
 A point is a fixed position
 v= [x, y,] T
 p = (a,b)
v
Vector Addition
 We can add vectors to vectors = new vector
 V1+v2 = [x1+x2, y1+y2]T
v2
v1
v1+v2
v1
v2
Vector Addition
 Add a vector to a point to obtain a new point.
 p=[1,1]T
p’
 v = [2,2]T
p’ = ?
What is happening here?
v
p
Confusing Points and
Vectors
Consider the point and the vector
P = P0 + b1v1+ b2v2 +….+bnvn
v=a1v1+ a2v2 +….+anvn
They appear to have the similar representations
p=[b1 b2 b3]
v=[a1 a2 a3]
v
which confuses the point with the vector
v
A vector has no position
p
Vectors can be placed anywhere
point: fixed
Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
6
Vector Multiplication
 Dot product
 dot(a,b) = ax*bx + ay*by)
 =
Scalar Multiplication
 v*s = [vx*s, vy*s] T
v
v*s
Vector Length
 How to make a vector unit length (normalize) ?
Coordinate Systems
 Consider a basis v1, v2,…., vn
 e.g. 3d space with 3 vectors pointing in the directions of
each axis
 A vector is written v=a1v1+ a2v2 +….+anvn
 The list of scalars {a1, a2, …. an}is the
representation of v with respect to the given basis
 a 1as
 a row or
 We can write the representation
 
a
column array of scalars
 2
a1 a2 …. an]T=
a=[
 . 
a 
n
 
 
Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
10
In 3D
 v=a1v1+ a2v2 + a3v3
v2
v
v3
v1
Example
 v=2v1+3v2-4v3
 a=[2 3 –4]T
 Note that this representation is with respect
to a particular basis
 For example, in OpenGL we start by
representing vectors using the object basis
but later the system needs a representation
in terms of the camera or eye basis
Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
12
Coordinate Systems
 Which is correct?
v
v
 Both are because vectors have no fixed
location
Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
13
Frames
 A coordinate system is insufficient to
represent points
 We can add a single point, the origin, to the
basis vectors to form a frame
v2
v1
P0
v3
Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
14
Representation in a Frame
 Frame determined by (P0, v1, v2, v3)
 Within this frame, every vector can be written
as
v=a1v1+ a2v2 +….+anvn
 Every point can be written as
P = P0 + b1v1+ b2v2 +….+bnvn
Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
15
What is a matrix?
 Theorem 1: A matrix has nothing to do with
Keanu Reeves (probably)
 m x n array of scalars
M=
A Frame in Matrix Form
 Where P0 is the origin of the frame M:
v2
v1
P0
v3
Matrix Operations
 Scalar multiplication, addition, matrix-matrix
multiplication…
 In this class, we really only care about:
 matrix-matrix multiplications with square (m x m)
matrices
 matrix-point multiplication
Matrix-Point Multiplication
Matrix-Matrix Multiplication
Does A*B = B*A?
What does the identity do?
Example
Properties of Matrices
 Associative
 A(BC) = (AB)C
 NOT commutative (usually)
 AB = BA
 However,
 IA = AI = A
What are matrices used for
in CG?
 Transformations:
 Rotation, Translation, Scale, Shear
Download