You are on page 1of 1

3d Maths Cheat Sheet Matrix * Matrix Column-Order Homogeneous Matrix

Each cell (row, col) in AB is:


P n
A(row, 1) ∗ B(1, col) + · · · + A(row, n) ∗ B(n, col) Commonly used in OpenGLmaths libraries
Vectors i=1
Wherehn is dimensionality

Xx Yx Zx Tx

Vx

ih iof matrix.
h i Xy Yy Zy Ty   Vy 
Vector Addition AB =
a b e f
=
ae + bg af + bh v0 = 
c d g h ce + dg cf + dh Xz Yz Zz Tz Vz
The sum of 2 vectors completes the triangle. 0 0 0 1 1

Translation, Scaling, and Rotation


   
also a = c − b and b = c − a 1 0 0 Tx Sx 0 0 0
0 1 0 Ty  0 Sy 0 0
column order T =  S= 
Unit Vectors - “Normalised” Vectors 0 0 1 Tz 0 0 Sz 0
(rows of A with columns of B) 0 0 0 1 0 0 0 1
Used to represent a direction or normal. Length of 1.  
~
Matrix Determinant 1 0 0 0
 = A~ ||A|| 0 cos(θ) −sin(θ) 0 
~ is the length or magnitude of A.
~ For a 2x2 or 3x3 matrix use the Rule of Sarrus; add products of Rx =  (column-order)
Where ||A|| 0 sin(θ) cos(θ) 0
top-left to bottom-right diagonals, subtract products of opposite
0 0 0 1
Dot Product of 2 Vectors diagonals.  
" # cos(θ) 0 sin(θ) 0
a b c
Can be used
Pn to get the angle between 2 vectors. 0 1 0 0 
~·B~ = M = d e f Its determinant |M | is: Ry =  (column-order)
A A B = A1 B1 + A2 B2 + · · · + An Bn −sin(θ) 0 cos(θ) 0
i=1 i i g h i
The dot product returns a single scalar value. θ = arccos(Â · B̂) 0 0 0 1
|M | = aei + bf g + cdh − ceg − bdi − af h
cos(θ) −sin(θ) 0
 
~ B
A· ~ 0
θ = arccos( ~ ~ ) For 4x4 use Laplace Expansion; each top-row value * the 3x3 matrix
||A|||| B|| sin(θ) cos(θ) 0 0 
made of all other rows and columns: Rz =  (column-order)
Where arccos is inverse cosine cos−1 . 0 0 1 0
|M | = aM1 − bM2 + cM3 − dM4
0 0 0 1
Cross Product of 2 Vectors See http://www.euclideanspace.com/maths/algebra/matrix/
functions/determinant/fourD/index.htm View Matrix
Produces a vector perpendicular to the plane containing the 2
vectors. Matrix Transpose 
Rx Ry Rz −Px

Flip matrix over its main diagonal. In special case of orthonormal Ux Uy Uz −Py 
xyz matrix then inverse is the transpose. Can use to switch V =  (column-order)
−Fx −Fy −Fz −Pz
between
" row-major # and column-major
" # matrices. 0 0 0 1
a b c a d g Where U is a vector pointing up, F forward, and P is world position
M = d e f MT = b e h of camera.  
g h i c f i 1 0 0 0
0 0 −1 0 
Matrix Inverse Bird’s-eye view V = 
" # " # " #
a1 b1 a2 b3 − a3 b2 0 1 0 0
a2 × b2 = a3 b1 − a1 b3 Use an inverse matrix to reverse its transformation, or to 0 0 0 1
a3 b3 a1 b2 − a2 b1 transform relative to another object.
To compute surface normals from 2 edges: M M −1 = I Where I is the identity matrix.
If the determinant of a matrix is 0, then there is no inverse. The Projection Matrix
N = normalize (cross (A, B));
inverse can be found by multiplying the determinant with a large  
Sx 0 0 0
Matrices matrix of cofactors. For the long formula see
0 Sy 0 0 
http://www.cg.info.hiroshima-cu.ac.jp/~miyazaki/ P = (column-order)
Identity Matrix 0 0 Sz Pz
knowledge/teche23.html
0 0 −1 0
All 0,"except the top-left to bottom-right diagonal. Use the transpose of an inverse model matrix to transform
Sx = (2 ∗ near)/(range ∗ aspect + range ∗ aspect)
normals: n0 = n(M −1 )T
#
1 0 0 Sy = near/range
I3 = 0 1 0 Sz = −(f ar + near)/(f ar − near)
0 0 1 Homogeneous Matrices
Pz = −(2 ∗ f ar ∗ near)/(f ar − near)
if AB = I then A is the inverse of B and vice versa. Row-Order Homogeneous Matrix range = tan(f ov/2) ∗ near
Commonly used in Direct3D
 maths libraries
Matrix * Vector Xx Xy Xz 0

" #" # " # revision 4. 5 Oct 2012
a b c x ax + by + cz 0
  Yx Y y Yz 0 Dr Anton Gerdelan, apg@scss.tcd.ie, Trinity College Dublin, Ireland.
d e f y = dx + ey + f z v = Vx Vy Vz 1  
Zx Zy Zz 0 LATEX template from http://www.stdout.org/∼winston/latex/
g h i z gx + hy + iz Tx Ty Tz 1 Thanks Michaël, Amoss, and Veronica!

You might also like