Académique Documents
Professionnel Documents
Culture Documents
Vectors
Vector Addition
The sum of 2 vectors completes the triangle.
Matrix * Matrix
Each cell (row, col) in AB is:
P
n
also a = c b and b = c a
B)
~ B
~
A
~
~ )
||A||||
B||
"
"
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
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
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
Multiply affine transformations into a 4d matrix. Order is important.
Commonly
used in OpenGLmaths
libraries
Xx Yx Zx Tx
Vx
Xy Yy Zy Ty Vy
v0 =
Xz Yz Zz Tz
Vz
0
0
0
1
1
v 0 = T Rv (change facing and position)
v 0 = RT v (rotate around a point)
Matrix Inverse
"
1
0
0
0
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
Tx
Sx
0
Ty
0
Sy
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
V =
(column-order)
Fx Fy Fz Pz
0
0
0
1
Where U is a vector pointing up, F forward, and P is world position
of camera. Remember
transformations.
to multiply to combine
1 0
0
0
0 0 1 0
Birds-eye view V =
(multipy T 1 to move)
0 1
0
0
0 0
0
1
V = T 1 R1 (column order: orbit camera around a point)
V = R1 T 1 (column order: orient camera and change position)
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