Presentation is loading. Please wait.

Presentation is loading. Please wait.

Linear Transformations and Matrices Jim Van Verth Lars M. Bishop

Similar presentations


Presentation on theme: "Linear Transformations and Matrices Jim Van Verth Lars M. Bishop"— Presentation transcript:

1 Linear Transformations and Matrices Jim Van Verth (jim@essentialmath.com) Lars M. Bishop (lars@essentialmath.com)

2 Essential Math for Games Transformation Have some geometric data How to apply functions to it? Also desired: combine multiple steps into single operation For vectors: linear transformations

3 Essential Math for Games Transformations A transformation T : V W is a function that maps elements from vector space V to W The function f(x, y) = x 2 + 2y is a transformation because it maps R 2 into R

4 Essential Math for Games Linear Transformation Two basic properties: T(x + y) = T(x) + T(y) T(ax) = aT(x) Follows that T(0) = 0 T(ax+y) = aT(x) + T(y)

5 Essential Math for Games Linear Transformations Basis vectors span vector space Know where basis goes, know where rest goes So we can do the following: Transform basis Store as columns in a matrix Use matrix to perform linear transforms

6 Essential Math for Games Linear Transforms Example: (1,0) maps to (1,2) (0,1) maps to (2,1) Matrix is

7 Essential Math for Games What is a Matrix? Rectangular m x n array of numbers M rows by n columns If n=m, matrix is square

8 Essential Math for Games Matrix Concepts Number at row i and column j of matrix A is element A ij Elements in row i make row vector Elems in column j make column vector If at least one A ii (diagonal from upper left to lower right) are non-zero and all others are zero, is diagonal matrix

9 Essential Math for Games Transpose Represented by A T Swap rows and columns along diagonal A T ij = A ji Diagonal is invariant

10 Essential Math for Games Transpose Transpose swaps transformed basis vectors from columns to rows Useful identity

11 Essential Math for Games Transforming Vectors Represent vector as matrix with one column # of components = columns in matrix Take dot product of vector w/each row Store results in new vector

12 Essential Math for Games Transforming Vectors Example: 2D vector Example: 3D vector to 2D vector

13 Essential Math for Games Row Vectors Can also use row vectors Transformed basis stored as rows Dot product with columns Pre-multiply instead of post-multiply If column default, represent row vector by v T

14 Essential Math for Games Row vs. Column Using column vectors, others use row vectors Keep your order straight! Transpose to convert from row to column (and vice versa) Row vector order (DirectX) Column vector order (us, OpenGL)

15 Essential Math for Games Matrix Product Want to combine transforms What matrix represents ? Idea: Columns of matrix for S are xformed basis Transform again by T

16 Essential Math for Games Matrix Product In general, element AB ij is dot product of row i from A and column j from B or

17 Essential Math for Games Matrix product (contd) Number of rows in A must equal number of columns in B Generally not commutative Is associative

18 Essential Math for Games Block Matrices Can represent matrix with submatrices Product of block matrix contains sums of products of submatrices

19 Essential Math for Games Identity Identity matrix I is square matrix with main diagonal of all 1s Multiplying by I has no effect A I = A

20 Essential Math for Games Inverse A -1 is inverse of matrix A such that A -1 reverses what A does A is orthogonal if A T = A -1 Component vectors are at right angles and unit length I.e. orthonormal basis

21 Essential Math for Games Computing Inverse Only square matrices have inverse Inverse doesnt always exist Zero row, column means no inverse Use Gaussian elimination or Cramers rule (see references)

22 Essential Math for Games Computing Inverses Most interactive apps avoid ever computing a general inverse Properties of the matrices used in most apps can simplify inverse If you know the underlying structure of the matrix, you can use the following:

23 Essential Math for Games Computing Inverse If orthogonal, A -1 = A T Inverse of diagonal matrix is diagonal matrix with A -1 ii = 1/A ii If know underlying structure can use Well use this to avoid explicit inverses

24 Essential Math for Games Storage Format Row major Stored in order of rows Used by DirectX

25 Essential Math for Games Storage Format (contd) Column Major Order Stored in order of columns Used by OpenGL, and us

26 Essential Math for Games Storage Format (contd) Note: storage format not the same as multiplying by row vector Same memory footprint: Matrix for multiplying column vectors in column major format Matrix for multiplying row vectors in row major format I.e. two transposes return same matrix

27 Essential Math for Games System of Linear Equations Define system of m linear equations with n unknowns b 1 = a 11 x 1 + a 12 x 2 + … + a 1n x n b 2 = a 21 x 1 + a 22 x 2 + … + a 2n x n … b m = a m1 x 1 + a m2 x 2 + … + a mn x n

28 Essential Math for Games System of Linear Equations Matrix multiplication encapsulates linear system

29 Essential Math for Games Matrix multiplication encapsulates linear system Solve for x Multiplying by inverse imprecise Use Gaussian elimination, or other methods (see refs) System of Linear Equations

30 Essential Math for Games References Anton, Howard and Chris Rorres, Elementary Linear Algebra, 7 th Ed, Wiley & Sons, 1994. Axler, Sheldon, Linear Algebra Done Right, Springer Verlag, 1997. Blinn, Jim, Notation, Notation, Notation, Morgan Kaufmann, 2002.


Download ppt "Linear Transformations and Matrices Jim Van Verth Lars M. Bishop"

Similar presentations


Ads by Google