Upload
others
View
9
Download
0
Embed Size (px)
Citation preview
Mathematics for Computer Graphics
Outline – Linear Algebra topicsOutline Linear Algebra topics
• Scalars• Vector Space– Scalars and vectors
• Affine Space– Scalars, vectors, and points
• Euclidean Space• Euclidean Space– Scalars, vectors, points– Distance metric
• Projections• Matrix representations and operations
Scalars• Scalar – a number
Ex: the scale weight or magnitude of something– Ex: the scale, weight, or magnitude of something
• Two Fundamental Operationsdd d l l– Addition and multiplication
SSS , ,,
Commutative
Associative
Distributive
Scalars• Two Special Scalars
Additi id tit 0 lti li ti id tit 1– Additive identity: 0, multiplicative identity: 1
00 11
– Additive inverse 0
–Multiplicative inverse 1 11
2D scalar field2D scalar field
2D array of scalar values2D array of scalar values
In C# the data structureIn C#, the data structure might look something like this:
float [,] temps;[,] p ;temps = new float[50,50];// (allocate after declaring)// (allocate after declaring)
http://upload.wikimedia.org/wikipedia/commons/a/a8/Scalar_field.png
Vector spaceVector space
• Two Entities: Scalars and VectorsTwo Entities: Scalars and Vectors• Vectors
Di t d li t– Directed line segments– n‐tuples of scalars– Two operations• vector‐vector addition
l t lti li ti• scalar‐vector multiplication
• Zero Vector0
Directed line segments 00
vv
vv
Vector spaceVector space
• In vector space two vectors are equal if they areIn vector space, two vectors are equal if they are represented with the same n‐tuple
Ex: (1 2 3) = (1 2 3)– 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 operationsVector space operations
• Vectors = n‐tuples vvvvVectors = n tuples– Vector‐vector addition
110 ,,, nvvvv
111100
110110
,,,,,,,,,
nn
nn
vuvuvuvvvuuuvu
– Scalar‐vector multiplication
– Vector decomposition 110 ,,, nvvvv
111100 nn uuuu
Vector space operations
• Scalar‐Vector Multiplicationu and v: vectors, α and β: scalars
vuvu
Scalar-vector multi.
uuu
• Vector Vector Addition• 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 anddirection, not position
• Coordinate SystemId ti l t
y– Origin: a particular reference point
Identical vectors
Arbitraryplacementof basis
Basisvectorslocated
of basisvectors
at theorigin
Coordinate systemCoordinate system
d k l 2 3 diBoardwork examples: 1D, 2D, 3D coordinate axes
Unity uses left‐handed coordinate system with +x being right and +y being upg g y g p
Affine SpacesAffine 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
• Vector point addition operation
QPv
• Vector‐point addition operation
QvP Head-to-tail axiom for points
RPRQQP
• Frame: a Point and a Set of Vectors– All vectors and points in the space are defined relative to these
0P 110 ,,, nvvv
V t
1111000
111100
nn
nn
vvvPPvvvv
Vector
Point
Euclidean SpacesEuclidean Spaces• Affine space does not include an operation or metric for distance between points
• Create a new operation: Inner (dot) Product• Create a new operation: Inner (dot) Product– Input: two vectors Output: scalar– α, β : scalars u, v, w : vectors
– Properties we want:
wvwuwvu
uvvu
0 if 0
000vvv
wvwuwvu
For orthogonal vectors0 00
0 vu
Euclidean Spaces – dot productEuclidean Spaces dot product• If we can multiply two n‐tuples, this implies
– Magnitude (length) of a vector vvv
– Distance between two points QPQPQP
– Measure of the angle between two vectors• cosθ = 0 orthogonal
cosvuvu
• cosθ = 1 parallel
• Computation of dot productp p
111100
1
0...
nn
n
iii vuvuvuvuvu
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,Given vectors v and w, decompose w into two parts, one parallel to v and one orthogonal to v
uvw
vvvuvvvw
Projection of onevector onto anothervv
vw
vvvvwwvwu
MatricesMatrices
• DefinitionsDefinitions• Matrix Operations
d C l i• Row and Column Matrices• Change of Representation• Relating matrices and vectors
What is a Matrix?What is a Matrix?• A matrix is a set of elements, organized into rows and columns
b
rows
dcba
columns
dc
DefinitionsDefinitions• 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 1010 mjniaElement
T i h i h d l f i
1,,0 ,1,,0 , mjnia ij ijaA
– Transpose: interchanging the rows and columns of a matrix
jiT aA
b• Column Matrices and Row Matrices– Column matrix (n x 1 matrix):Row matrix (1 x matrix)
1
0
i
bb
b
b– Row matrix (1 x n matrix):
1nb
110 ... nT bbbb
Matrix OperationsMatrix Operations
• Scalar‐Matrix Multiplication a AScalar Matrix Multiplication–Multiply every element by the scalar
• Matrix Matrix Addition
ijaA
ba BAC• Matrix‐Matrix Addition– Add elements with same index
ijij ba BAC
• Matrix‐Matrix Multiplication– A: n x l matrix, B: l x m C: n x m matrix
1l
ijcABC cij = the sum of multiplying elements in row i of matrix a
1
0
l
kkjikij bac times elements in column j of
matrix b
Matrix Operation ExamplesMatrix Operation Examples
fbeafeba
hdgcf
hgf
dc
hdfbea
hfe
dba
hdgchgdc
dhcfdgcebhafbgae
hgfe
dcba
dhcfdgcehgdc
Matrix OperationsMatrix Operations
• Properties of Scalar‐Matrix Multiplication AA
p p
• Properties of Matrix‐Matrix Addition
AA
ABBA– Commutative:– Associative:
• Properties of Matrix‐Matrix Multiplication
ABBA CBACBA
p p
BAAB
CABBCA
• Identity Matrix I (Square Matrix)
BAAB
if1 ji AAI 0001
otherwise 0if 1
,ji
aa ijijIBIBAAI
1000010000100001
Matrix Multiplication OrderMatrix Multiplication Order
• Is AB = BA? Maybe but maybe not!Is AB = BA? Maybe, but maybe not!
...bgaefeba
...fceabafe
......hgdc
......dchg
• In general, matrix multiplication is NOT commutative!
• The order of matrix multiplications is important!important!
Row and Column Matrices + pointsRow and Column Matrices + points
• Column Matrix
x By convention
we will useColumn Matrix
zyp we will use
column matrices for points
– Row matrix
C t ti zyxT p
• Concatenations– Associative ABCpp
App
• By Row Matrix TTT ABAB TTTTT ABCpp
Vector OperationsVector Operations
• Vector: 1 x N matrix
Vector: 1 x N matrix• Interpretation: a line in N dimensional
ba
in N dimensional spaceD P d d
cbv
• Dot Product and Magnitude
i
cyoperations y
v
x
Vectors: Dot ProductVectors: Dot Product
d Thi k f th d t cfbead
fed
cbaabba T
Think of the dot product as a matrix multiplication
bbT 2The magnitude is the dot
d t f t ithccbbaaaaa T product of a vector with itself
)cos(baba
If a and b are both length one, the angle between them is the cos-1 of their dot product
Inverse of a MatrixInverse of a Matrix
• Identity matrix: 001Identity matrix: AI = A
• Some matrices have an
010001
I• Some matrices have an inverse, such that:AA‐1 = I
100
AA 1 = I
101 101
110101
A
110101
1A 100
100
Inverse of a MatrixInverse of a Matrix
• Some matrices do not have an inverseSome matrices do not have an inverse
000
cba
100010A
ihfedA 1
100 ihg
AA‐100 = 0 * a + 0 * d + 0 * g = 0 ≠ 1
Inverse of Matrix ConcatenationInverse of Matrix Concatenation
• Inversion of concatenationsInversion of concatenations(ABC)‐1 = C‐1B‐1A‐1
A * B * C * X = IA * B * C * C 1 A * BA * B * C * C‐1 = A * B
A * B * B‐1 = AA * A‐1 = I
Order is important so X = C‐1B‐1A‐1Order is important, so X C B A
SummarySummary
• Primitives: scalars, vectors, points
• Operations: addition and multiplication
• Matrix representation and operationsMatrix representation and operations