Professional Documents
Culture Documents
Vectors
Matrix * Matrix
Each cell (row, col) in AB is:
P
n
Vector Addition
The sum of 2 vectors completes the triangle.
1
0
0
0
also a = c b and b = c a
B)
~ B
~
A
~
~ )
||A||||
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.
#
"
a b c
d e f
Its determinant |M | is:
M =
g h i
|M | = aei + bf g + cdh ceg bdi af h
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.
a b c
a d g
d e f
b e h
M =
MT =
g h i
c f i
"
"
"
a1
b1
a2 b3 a3 b2
a2
b2
a3 b1 a1 b3
=
a3
b3
a1 b2 a2 b1
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.
#
1 0 0
0 1 0
I3 =
0 0 1
if AB = I then A is the inverse of B and vice versa.
Matrix
* Vector
"
#" #
a
d
g
b
e
h
c
f
i
x
y
z
"
=
ax + by + cz
dx + ey + f z
gx + hy + iz
Commonly
used in OpenGLmaths
libraries
Vx
Xx Yx Zx Tx
Xy Yy Zy Ty Vy
v0 =
Vz
Xz Yz Zz Tz
1
0
0
0
1
Matrix Inverse
Use an inverse matrix to reverse its transformation, or to
transform relative to another object.
M M 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: n0 = n(M 1 )T
Homogeneous Matrices
Row-Order Homogeneous Matrix
Commonly used in Direct3D
maths libraries
Xx Xy Xz 0
Yx Y y Yz 0
0
v = Vx Vy Vz 1
Zx Zy Zz 0
Tx
Ty
Tz 1
0 0
1 0
column order T =
0 1
0 0
1
0
0
0 cos() sin()
Rx =
0 sin()
cos()
0
0
0
cos()
0 sin()
0
1
0
Ry =
sin() 0 cos()
0
0
0
cos() sin() 0
sin()
cos()
0
Rz =
0
0
1
0
0
0
View Matrix
Sx
0
Tx
0
Sy
Ty
S=
0
0
Tz
0
0
1
0
0
(column-order)
0
1
0
0
(column-order)
0
1
0
0
(column-order)
0
1
0
0
Sz
0
0
0
0
1
Rx
Ry
Rz
Px
Ux
Uy
Uz
Py
(column-order)
V =
Fx Fy Fz Pz
0
0
0
1
Where U is a vector pointing up, F forward, and P is world position
of camera.
1 0
0
0
0 0 1 0
Birds-eye view V =
0 1
0
0
0 0
0
1
Projection Matrix
Sx
0
0
0
0
Sy
0
0
P =
(column-order)
0
0
Sz Pz
0
0
1
0
Sx = (2 near)/(range aspect + range aspect)
Sy = near/range
Sz = (f ar + near)/(f ar near)
Pz = (2 f ar near)/(f ar near)
range = tan(f ov/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
el, Amoss, and Veronica!