Linear Algebra Review for Computer Graphics
-
Upload
jamal-richard -
Category
Documents
-
view
77 -
download
3
description
Transcript of Linear Algebra Review for Computer Graphics
![Page 1: Linear Algebra Review for Computer Graphics](https://reader036.fdocuments.net/reader036/viewer/2022081417/56812cdd550346895d91a19f/html5/thumbnails/1.jpg)
Linear Algebra Review for Computer Graphics
Matt BoggusCSE 3451/5541
![Page 2: Linear Algebra Review for Computer Graphics](https://reader036.fdocuments.net/reader036/viewer/2022081417/56812cdd550346895d91a19f/html5/thumbnails/2.jpg)
Outline
• Coordinate Spaces• Primitives– Scalars– Vectors– Points
• Operations• Matrices
![Page 3: Linear Algebra Review for Computer Graphics](https://reader036.fdocuments.net/reader036/viewer/2022081417/56812cdd550346895d91a19f/html5/thumbnails/3.jpg)
Coordinate system
Boardwork examples: 1D, 2D, 3D coordinate systems
![Page 4: Linear Algebra Review for Computer Graphics](https://reader036.fdocuments.net/reader036/viewer/2022081417/56812cdd550346895d91a19f/html5/thumbnails/4.jpg)
Coordinate system in Unity
• 3D, left-handed coordinate system
![Page 5: Linear Algebra Review for Computer Graphics](https://reader036.fdocuments.net/reader036/viewer/2022081417/56812cdd550346895d91a19f/html5/thumbnails/5.jpg)
Scalars• Scalar value – a number (integer or real)• Ex: the scale, weight, or magnitude of something
• Scalar field – 2D array of scalar values
C# example:
float [,] temps;temps = new float[50,50];
http://upload.wikimedia.org/wikipedia/commons/a/a8/Scalar_field.png
![Page 6: Linear Algebra Review for Computer Graphics](https://reader036.fdocuments.net/reader036/viewer/2022081417/56812cdd550346895d91a19f/html5/thumbnails/6.jpg)
Scalar operations and terms
• Two fundamental operations– Addition and multiplication
SSS , ,,
Associative
Commutative
Distributive
![Page 7: Linear Algebra Review for Computer Graphics](https://reader036.fdocuments.net/reader036/viewer/2022081417/56812cdd550346895d91a19f/html5/thumbnails/7.jpg)
Scalar operations and terms• Additive identity 0
• Multiplicative identity: 1
• Additive inverse
• Multiplicative inverse
11
1
0
11
00
![Page 8: Linear Algebra Review for Computer Graphics](https://reader036.fdocuments.net/reader036/viewer/2022081417/56812cdd550346895d91a19f/html5/thumbnails/8.jpg)
Vectors• Vector – a quantity possessing both magnitude
and direction• Visualized as directed line segments
• Mathematically described as n-tuples of scalars– Examples: (0,0,0) (x,y) (r,g,b,a)
![Page 9: Linear Algebra Review for Computer Graphics](https://reader036.fdocuments.net/reader036/viewer/2022081417/56812cdd550346895d91a19f/html5/thumbnails/9.jpg)
Vector operations – mathematically• Vectors = n-tuples– Vector-vector addition
– Scalar-vector multiplication
– Vector decomposition
110 ,,, nvvvv
111100
110110
,,,
,,,,,,
nn
nn
vuvuvu
vvvuuuvu
110 ,,, nvvvv
111100 nn uuuu
Numeric examples of vector operations
![Page 10: Linear Algebra Review for Computer Graphics](https://reader036.fdocuments.net/reader036/viewer/2022081417/56812cdd550346895d91a19f/html5/thumbnails/10.jpg)
Vector operations – intuitively• Vector-Vector Addition– Visualize using head-to-tail axiom
• Scalar-vector multiplication– Resize (scale) the directed line segment α > 1 length increases 0 > α > 1 length decreases α < 0 reverse direction
Head-to-tail axiom
Scalar-vector multi.
![Page 11: Linear Algebra Review for Computer Graphics](https://reader036.fdocuments.net/reader036/viewer/2022081417/56812cdd550346895d91a19f/html5/thumbnails/11.jpg)
Points• Point – a location or position• Visualized as dots
• Mathematically described as n-tuples of scalars– Examples: (0,0,0) (x,y) (r,g,b,a)– Note: points and vectors have the same
representation!
![Page 12: Linear Algebra Review for Computer Graphics](https://reader036.fdocuments.net/reader036/viewer/2022081417/56812cdd550346895d91a19f/html5/thumbnails/12.jpg)
Coordinate system or frame
• Origin – a point– Indicates the “center” of the coordinate systems– Other points are defined relative to the origin
• Basis vectors– A set of linearly independent vectors– None of them can be written as a linear
combination of the others
Arbitraryplacement
of basisvectors
Basisvectorslocatedat theorigin
![Page 13: Linear Algebra Review for Computer Graphics](https://reader036.fdocuments.net/reader036/viewer/2022081417/56812cdd550346895d91a19f/html5/thumbnails/13.jpg)
Vectors and points in a coordinate system
• Coordinate frame defined by point P0 , set of vectors
• A vector v is
• A point P is
• Note: α and β indicate scalar values
110 ,,, nvvv
1111000 nn vvvPP
111100 nn vvvv
![Page 14: Linear Algebra Review for Computer Graphics](https://reader036.fdocuments.net/reader036/viewer/2022081417/56812cdd550346895d91a19f/html5/thumbnails/14.jpg)
Practice problem
• Given a point P = (2,-5,1) in a right handed coordinate system, what is the point is a left handed coordinate system?
![Page 15: Linear Algebra Review for Computer Graphics](https://reader036.fdocuments.net/reader036/viewer/2022081417/56812cdd550346895d91a19f/html5/thumbnails/15.jpg)
Point-Vector operations• P and Q are points, v is a vector• Point-point subtraction operation
• Vector-point addition operation
QPv
QvP
RPRQQP
![Page 16: Linear Algebra Review for Computer Graphics](https://reader036.fdocuments.net/reader036/viewer/2022081417/56812cdd550346895d91a19f/html5/thumbnails/16.jpg)
Working toward a distance metric
• The previous operations do not include a way to estimate distance between points
• Create a new operation: Inner (dot) Product– Input: two vectors Output: scalar
– Properties we want:
For orthogonal vectors
0
if 0
00
0vvv
wvwuwvu
uvvu
0vu
![Page 17: Linear Algebra Review for Computer Graphics](https://reader036.fdocuments.net/reader036/viewer/2022081417/56812cdd550346895d91a19f/html5/thumbnails/17.jpg)
Dot product logic
• If we can multiply two n-tuples, this implies
– Magnitude (length) of a vector
– Distance between two points
QPQPQP
vvv
![Page 18: Linear Algebra Review for Computer Graphics](https://reader036.fdocuments.net/reader036/viewer/2022081417/56812cdd550346895d91a19f/html5/thumbnails/18.jpg)
Dot product computation
• Dot product of two vectors, u and v
• Ex: (5,4,2) (1,0,1) = 5 * 1 + 4 * 0 + 2 * 1 = 7∙• With some algebra we find that the dot product
is equivalent to where θ is the angle between the two vectors–cosθ = 0 orthogonal–cosθ = 1 parallel
111100
1
0
...
nn
n
iii vuvuvuvuvu
cosvuvu
![Page 19: Linear Algebra Review for Computer Graphics](https://reader036.fdocuments.net/reader036/viewer/2022081417/56812cdd550346895d91a19f/html5/thumbnails/19.jpg)
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
Projection of onevector onto another
uvw
vvvuvvvw
vv
vw
vvv
vwwvwu
![Page 20: Linear Algebra Review for Computer Graphics](https://reader036.fdocuments.net/reader036/viewer/2022081417/56812cdd550346895d91a19f/html5/thumbnails/20.jpg)
Cross product
• Another formula that varies as the angle between vectors change
http://en.wikipedia.org/wiki/Cross_product
![Page 21: Linear Algebra Review for Computer Graphics](https://reader036.fdocuments.net/reader036/viewer/2022081417/56812cdd550346895d91a19f/html5/thumbnails/21.jpg)
Matrices
• Definitions• Matrix Operations• Row and Column Matrices• Change of Representation• Relating matrices and vectors
![Page 22: Linear Algebra Review for Computer Graphics](https://reader036.fdocuments.net/reader036/viewer/2022081417/56812cdd550346895d91a19f/html5/thumbnails/22.jpg)
What is a Matrix?
dc
ba
• A matrix is a set of elements, organized into rows and columns
rows
columns
![Page 23: Linear Algebra Review for Computer Graphics](https://reader036.fdocuments.net/reader036/viewer/2022081417/56812cdd550346895d91a19f/html5/thumbnails/23.jpg)
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
– Transpose: interchanging the rows and columns of a matrix
• Column Matrices and Row Matrices– Column matrix (n x 1 matrix):– Row matrix (1 x n matrix):
1,,0 ,1,,0 , mjniaij
ijaA
jiT aA
1
1
0
n
i
b
b
b
b
b
110 ... nT bbbb
![Page 24: Linear Algebra Review for Computer Graphics](https://reader036.fdocuments.net/reader036/viewer/2022081417/56812cdd550346895d91a19f/html5/thumbnails/24.jpg)
Matrix Operations
• Scalar-Matrix Multiplication– Multiply every element by the scalar
• 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
ija A
ijij ba BAC
1
0
l
kkjikij
ij
bac
cABC cij = the sum of multiplying elements in row i of matrix a times elements in column j of matrix b
![Page 25: Linear Algebra Review for Computer Graphics](https://reader036.fdocuments.net/reader036/viewer/2022081417/56812cdd550346895d91a19f/html5/thumbnails/25.jpg)
Matrix Operation Examples
hdgc
fbea
hg
fe
dc
ba
hdgc
fbea
hg
fe
dc
ba
dhcfdgce
bhafbgae
hg
fe
dc
ba
![Page 26: Linear Algebra Review for Computer Graphics](https://reader036.fdocuments.net/reader036/viewer/2022081417/56812cdd550346895d91a19f/html5/thumbnails/26.jpg)
Matrix Operations
• Properties of Scalar-Matrix Multiplication
• Properties of Matrix-Matrix Addition– Commutative:– Associative:
• Properties of Matrix-Matrix Multiplication
• Identity Matrix I (Square Matrix)
AA
AA
ABBA CBACBA
CABBCA
otherwise 0
if 1 ,
jiaa ijijI
BIB
AAI
1000
0100
0010
0001
![Page 27: Linear Algebra Review for Computer Graphics](https://reader036.fdocuments.net/reader036/viewer/2022081417/56812cdd550346895d91a19f/html5/thumbnails/27.jpg)
Matrix Multiplication Order
• Is AB = BA? Try it!
• Matrix multiplication is NOT commutative!• The order of series of matrix multiplications
is important!
hdgbhcga
fdebfcea
dc
ba
hg
fe
dhcfdgce
bhafbgae
hg
fe
dc
ba
![Page 28: Linear Algebra Review for Computer Graphics](https://reader036.fdocuments.net/reader036/viewer/2022081417/56812cdd550346895d91a19f/html5/thumbnails/28.jpg)
Inverse of a Matrix
• Identity matrix: AI = A
• Some matrices have an inverse, such that:AA-1 = I
100
010
001
I
100
110
101
A
100
110
1011A
![Page 29: Linear Algebra Review for Computer Graphics](https://reader036.fdocuments.net/reader036/viewer/2022081417/56812cdd550346895d91a19f/html5/thumbnails/29.jpg)
Inverse of a Matrix
• Do all matrices have a multiplicative inverse? Consider this example, try to solve for A-1:
AA-100 =
100
010
000
A
ihg
fed
cba
A 1
0 * a + 0 * d + 0 * g = 0 ≠ 1
Note: 1 is the element at 00 in the identity matrix
![Page 30: Linear Algebra Review for Computer Graphics](https://reader036.fdocuments.net/reader036/viewer/2022081417/56812cdd550346895d91a19f/html5/thumbnails/30.jpg)
Inverse of Matrix Concatenation
• Inversion of concatenations(ABC)-1 = ?
A * B * C * X = IA * B * C * C-1 = A * B
A * B * B-1 = AA * A-1 = I
Order is important, so X = C-1B-1A-1
![Page 31: Linear Algebra Review for Computer Graphics](https://reader036.fdocuments.net/reader036/viewer/2022081417/56812cdd550346895d91a19f/html5/thumbnails/31.jpg)
Row and Column Matrices + points
• Column Matrix
– Row matrix• Concatenations– Associative
• By Row Matrix
z
y
x
p
ABCpp
App
TTTTT
TTT
ABCpp
ABAB
zyxT p
By convention we will use column matrices for points
![Page 32: Linear Algebra Review for Computer Graphics](https://reader036.fdocuments.net/reader036/viewer/2022081417/56812cdd550346895d91a19f/html5/thumbnails/32.jpg)
Summary
• Primitives: scalars, vectors, points
• Operations: addition and multiplication
• Matrix representation and operations