Download 3d Maths Cheat Sheet and more Exams Algebra in PDF only on Docsity! 3d Maths Cheat Sheet Vectors Vector Addition The sum of 2 vectors completes the triangle. also a = c− b and b = c− a Unit Vectors - “Normalised” Vectors Used to represent a direction or normal. Length of 1. Â = ~A || ~A|| Where || ~A|| is the length or magnitude of ~A. Dot Product of 2 Vectors Can be used to get the angle between 2 vectors. ~A · ~B = ∑n i=1 AiBi = A1B1 +A2B2 + · · ·+AnBn The dot product returns a single scalar value. θ = arccos(Â · B̂) θ = arccos( ~A·~B || ~A||||~B|| ) Where arccos is inverse cosine cos−1. Cross Product of 2 Vectors Produces a vector perpendicular to the plane containing the 2 vectors. [ a1 a2 a3 ] × [ b1 b2 b3 ] = [ a2b3 − a3b2 a3b1 − a1b3 a1b2 − a2b1 ] To compute surface normals from 2 edges: N = normalize (cross (A, B)); Matrices Identity Matrix All 0, except the top-left to bottom-right diagonal. I3 = [ 1 0 0 0 1 0 0 0 1 ] if AB = I then A is the inverse of B and vice versa. Matrix * Vector[ a b c d e f g h i ][ x y z ] = [ ax+ by + cz dx+ ey + fz gx+ hy + iz ] Matrix * Matrix Each cell (row, col) in AB is:∑n i=1 A(row, 1) ∗B(1, col) + · · ·+A(row, n) ∗B(n, col) Where n is dimensionality of matrix. AB = [ a b c d ] [ e f g h ] = [ ae+ bg af + bh ce+ dg cf + dh ] (rows of A with columns of B) Matrix Determinant For a 2x2 or 3x3 matrix use the Rule of Sarrus; add products of top-left to bottom-right diagonals, subtract products of opposite diagonals. M = [ a b c d e f g h i ] Its determinant |M | is: |M | = aei+ bfg + cdh− ceg − bdi− afh For 4x4 use Laplace Expansion; each top-row value * the 3x3 matrix made of all other rows and columns: |M | = aM1 − bM2 + cM3 − dM4 See http://www.euclideanspace.com/maths/algebra/matrix/ functions/determinant/fourD/index.htm Matrix Transpose Flip matrix over its main diagonal. In special case of orthonormal xyz matrix then inverse is the transpose. Can use to switch between row-major and column-major matrices. M = [ a b c d e f g h i ] MT = [ a d g b e h c f i ] Matrix Inverse Use an inverse matrix to reverse its transformation, or to transform relative to another object. MM−1 = I Where I is the identity matrix. If the determinant of a matrix is 0, then there is no inverse. The inverse can be found by multiplying the determinant with a large matrix of cofactors. For the long formula see http://www.cg.info.hiroshima-cu.ac.jp/~miyazaki/ knowledge/teche23.html Use the transpose of an inverse model matrix to transform normals: n′ = n(M−1)T Homogeneous Matrices Row-Order Homogeneous Matrix Commonly used in Direct3D maths libraries v′ = [ Vx Vy Vz 1 ] Xx Xy Xz 0 Yx Yy Yz 0 Zx Zy Zz 0 Tx Ty Tz 1 Column-Order Homogeneous Matrix Commonly used in OpenGL maths libraries v′ = Xx Yx Zx Tx Xy Yy Zy Ty Xz Yz Zz Tz 0 0 0 1 Vx Vy Vz 1 Translation, Scaling, and Rotation column order T = 1 0 0 Tx 0 1 0 Ty 0 0 1 Tz 0 0 0 1 S = Sx 0 0 0 0 Sy 0 0 0 0 Sz 0 0 0 0 1 Rx = 1 0 0 0 0 cos(θ) −sin(θ) 0 0 sin(θ) cos(θ) 0 0 0 0 1 (column-order) Ry = cos(θ) 0 sin(θ) 0 0 1 0 0 −sin(θ) 0 cos(θ) 0 0 0 0 1 (column-order) Rz = cos(θ) −sin(θ) 0 0 sin(θ) cos(θ) 0 0 0 0 1 0 0 0 0 1 (column-order) View Matrix V = Rx Ry Rz −Px Ux Uy Uz −Py −Fx −Fy −Fz −Pz 0 0 0 1 (column-order) Where U is a vector pointing up, F forward, and P is world position of camera. Bird’s-eye view V = 1 0 0 0 0 0 −1 0 0 1 0 0 0 0 0 1 Projection Matrix P = Sx 0 0 0 0 Sy 0 0 0 0 Sz Pz 0 0 −1 0 (column-order) Sx = (2 ∗ near)/(range ∗ aspect+ range ∗ aspect) Sy = near/range Sz = −(far + near)/(far − near) Pz = −(2 ∗ far ∗ near)/(far − near) range = tan(fov/2) ∗ near revision 4. 5 Oct 2012 Dr Anton Gerdelan, apg@scss.tcd.ie, Trinity College Dublin, Ireland. LATEX template from http://www.stdout.org/∼winston/latex/ Thanks Michaël, Amoss, and Veronica!