linear algebra
Download
Report
Transcript linear algebra
6.837 Linear Algebra Review
Rob Jagnow
Monday, September 20, 2004
6.837 Linear Algebra Review
Overview
•
•
•
•
•
Basic matrix operations (+, -, *)
Cross and dot products
Determinants and inverses
Homogeneous coordinates
Orthonormal basis
6.837 Linear Algebra Review
Additional Resources
•
•
•
•
18.06 Text Book
6.837 Text Book
[email protected]
Check the course website for a
copy of these notes
6.837 Linear Algebra Review
What is a Matrix?
• A matrix is a set of elements, organized
into rows and columns
m×n matrix
n columns
m rows
a00
a
10
a01
a11
6.837 Linear Algebra Review
Basic Operations
• Transpose: Swap rows with columns
a b
M d e
g h
c
f
i
x
V y
z
a d
M T b e
c f
V T x
6.837 Linear Algebra Review
y
g
h
i
z
Basic Operations
• Addition and Subtraction
a
c
a
c
b e
d g
b e
A
d g
f a e b f
h c g d h
f a e b f
h c g d h
Just add elements
Just subtract elements
A
A
B
A+B
A
B
B
A-B
-B
A
6.837 Linear Algebra Review
A
-B
Basic Operations
• Multiplication
a b e
c d g
f ae bg
h ce dg
af bh
cf dh
Multiply each row
by each column
An m×n can be multiplied by an n×p
matrix to yield an m×p result
6.837 Linear Algebra Review
Multiplication
• 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 ...
...
• Heads up: multiplication is NOT commutative!
6.837 Linear Algebra Review
Vector Operations
• Vector: n×1 matrix
a
v b
c
• Interpretation:
a point or line in
n-dimensional space
• Dot Product, Cross
Product, and
Magnitude defined on
vectors only
y
v
x
6.837 Linear Algebra Review
Vector Interpretation
• Think of a vector as a line in 2D or 3D
• Think of a matrix as a transformation on a line
or set of lines
x' a b x
y ' c d y
6.837 Linear Algebra Review
V
V’
Vectors: Dot Product
• Interpretation: the dot product measures
to what degree two vectors are aligned
If A and B have length 1…
A
A
B
A·B = 0
A=B
A·B = 1
6.837 Linear Algebra Review
θ
A·B = cos θ
B
Vectors: Dot Product
d
A B ABT a b c e ad be cf
f
A AAT 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
The dot product is also related to
the angle between the two vectors
6.837 Linear Algebra Review
Vectors: Cross Product
• The cross product of vectors A and B is a vector C
which is perpendicular to A and B
• The magnitude of C is proportional to the sin of the
angle between A and B
• The direction of C follows the right hand rule if we are
working in a right-handed coordinate system
A B A B sin( )
A×B
B
A
6.837 Linear Algebra Review
Vectors: Cross Product
The cross-product can be computed as a
specially constructed determinant
A×B
A
iˆ
A B ax
bx
ˆj
ay
by
kˆ a y bz a z by
a z a z bx a xbz
bz a xby a y bx
B
6.837 Linear Algebra Review
Inverse of a Matrix
• Identity matrix:
AI = A
• Some matrices have an
inverse, such that:
AA-1 = I
• Inversion is tricky:
(ABC)-1 = C-1B-1A-1
Derived from noncommutativity property
1 0 0
I 0 1 0
0 0 1
6.837 Linear Algebra Review
Determinant of a Matrix
• Used for inversion
• If det(A) = 0, then A
has no inverse
• Can be found using
factorials, pivots, and
cofactors!
• Lots of interpretations
– for more info, take
18.06
a b
A
c
d
det( A) ad bc
1 d b
A
ad bc c a
1
6.837 Linear Algebra Review
Determinant of a Matrix
a b
d e
g h
c
f aei bfg cdh afh bdi ceg
i
a b
d e
g h
c a b
f d e
i g h
c a b
f d e
i g h
c
f
i
For a 3×3 matrix:
Sum from left to right
Subtract from right to left
Note: In the general case, the determinant has n! terms
6.837 Linear Algebra Review
Inverse of a Matrix
a b
d e
g h
c 1 0 0
f 0 1 0
i 0 0 1
1. Append the identity matrix
to A
2. Subtract multiples of the
other rows from the first
row to reduce the
diagonal element to 1
3. Transform the identity
matrix as you go
4. When the original matrix
is the identity, the identity
has become the inverse!
6.837 Linear Algebra Review
Homogeneous Matrices
• Problem: how to include translations in
transformations (and do perspective transforms)
• Solution: add an extra dimension
x' a00
y ' a
10
z ' a20
1 0
a01 a02 t x x
a11 a12 t y y
a21 a22 t z z
0
0 1 1
6.837 Linear Algebra Review
Orthonormal Basis
• Basis: a space is totally defined by a set of
vectors – any point is a linear combination
of the basis
• Orthogonal: dot product is zero
• Normal: magnitude is one
• Orthonormal: orthogonal + normal
• Most common Example: xˆ , yˆ , zˆ
6.837 Linear Algebra Review
Change of Orthonormal Basis
• Given:
y
v
x p
v
coordinate frames
xyz and uvn
point p = (px, py, pz)
u
u
y
x
y
v
• Find:
p
p = (pu, pv, pn)
n
z
6.837 Linear Algebra Review
u
x
Change of Orthonormal Basis
y
y
v y.u
v
y.v
u
u
x.v
x
x
n
x.u
z
x = (x . u) u + (x . v) v +
y = (y . u) u + (y . v) v +
z = (z . u) u + (z . v) v +
6.837 Linear Algebra Review
(x . n) n
(y . n) n
(z . n) n
Change of Orthonormal Basis
x = (x . u) u + (x . v) v +
y = (y . u) u + (y . v) v +
z = (z . u) u + (z . v) v +
(x . n) n
(y . n) n
(z . n) n
Substitute into equation for p:
p = (px, py, pz) = px x + py y + pz z
p = px [ (x . u) u + (x . v) v +
py [ (y . u) u + (y . v) v +
pz [ (z . u) u + (z . v) v +
6.837 Linear Algebra Review
(x . n) n ] +
(y . n) n ] +
(z . n) n ]
Change of Orthonormal Basis
p = px [ (x . u) u + (x . v) v +
py [ (y . u) u + (y . v) v +
pz [ (z . u) u + (z . v) v +
(x . n) n ] +
(y . n) n ] +
(z . n) n ]
Rewrite:
p = [ px (x . u) + py (y . u) + pz (z . u) ] u +
[ px (x . v) + py (y . v) + pz (z . v) ] v +
[ px (x . n) + py (y . n) + pz (z . n) ] n
6.837 Linear Algebra Review
Change of Orthonormal Basis
p = [ px (x . u) + py (y . u) + pz (z . u) ] u +
[ px (x . v) + py (y . v) + pz (z . v) ] v +
[ px (x . n) + py (y . n) + pz (z . n) ] n
p = (pu, pv, pn) = pu u + pv v + pn n
Expressed in uvn basis:
pu = px (x . u) + py (y . u) +
pv = px (x . v) + py (y . v) +
pn = px (x . n) + py (y . n) +
6.837 Linear Algebra Review
pz (z . u)
pz (z . v)
pz (z . n)
Change of Orthonormal Basis
pu = px (x . u) + py (y . u) +
pv = px (x . v) + py (y . v) +
pn = px (x . n) + py (y . n) +
pz (z . u)
pz (z . v)
pz (z . n)
In matrix form:
ux uy uz
pu
p v = vx vy vz
nx ny nz
pn
px
py
pz
6.837 Linear Algebra Review
where:
ux = x . u
uy = y . u
etc.
Change of Orthonormal Basis
ux uy uz
pu
pv = vx vy vz
nx ny nz
pn
px
py
pz
=
M
px
py
pz
What's M-1, the inverse?
xu xv xn
px
p y = yu yv yn
zu zv zn
pz
pu
pv
pn
ux = x . u = u . x = xu
6.837 Linear Algebra Review
M-1 = MT
Caveats
• Right-handed vs. left-handed coordinate systems
– OpenGL is right-handed
• Row-major vs. column-major matrix storage.
– matrix.h uses row-major order
– OpenGL uses column-major order
0 1 2 3
4 5 6 7
8 9 10 11
12
13
14
15
row-major
0 4 8 12
1 5 9 13
2 6 10 14
3
7
11
15
column-major
6.837 Linear Algebra Review
Questions?
?
6.837 Linear Algebra Review