Docsity

3d Maths Cheat Sheet, Exams of Algebra

Toggle sidebar
bg1
3d Maths Cheat Sheet
Vectors
Vector Addition
The sum of 2 vectors completes the triangle.
also a=c−band b=c−a
Unit Vectors - “Normalised” Vectors
Used to represent a direction or normal. Length of 1.
ˆ
A=~
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=Pn
i=1 AiBi=A1B1+A2B2+···+AnBn
The dot product returns a single scalar value. θ=arccos(ˆ
A·ˆ
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="100
010
001#
if AB =Ithen Ais the inverse of Band 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:
Pn
i=1 A(row, 1) ∗B(1, col) + ··· +A(row, n)∗B(n, col)
Where nis dimensionality of matrix.
AB =ha b
c d ih e f
g h i=hae +bg af +bh
ce +dg cf +dh i
(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 −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.
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=IWhere Iis 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
v0=VxVyVz1
XxXyXz0
YxYyYz0
ZxZyZz0
TxTyTz1
Column-Order Homogeneous Matrix
Commonly used in OpenGL maths libraries
v0=
XxYxZxTx
XyYyZyTy
XzYzZzTz
0 0 0 1
Vx
Vy
Vz
1
Translation, Scaling, and Rotation
column order T=
100Tx
010Ty
001Tz
0 0 0 1
S=
Sx0 0 0
0Sy0 0
0 0 Sz0
0 0 0 1
Rx=
1 0 0 0
0cos(θ)−sin(θ) 0
0sin(θ)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(θ)00
sin(θ)cos(θ) 0 0
0 0 1 0
0 0 0 1
(column-order)
View Matrix
V=
RxRyRz−Px
UxUyUz−Py
−Fx−Fy−Fz−Pz
0 0 0 1
(column-order)
Where Uis a vector pointing up, Fforward, and Pis 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=
Sx0 0 0
0Sy0 0
0 0 SzPz
0 0 −1 0
(column-order)
Sx= (2 ∗near)/(rang e ∗aspect +range ∗aspect)
Sy=near/range
Sz=−(far +near )/(far −near )
Pz=−(2 ∗far ∗near )/(far −near )
range =tan(f ov/2) ∗near
revision 4. 5 Oct 2012
Dr Anton Gerdelan, [email protected], Trinity College Dublin, Ireland.
L
A
T
E
X template from http://www.stdout.org/∼winston/latex/
Thanks Micha¨el, Amoss, and Veronica!

Partial preview of the text

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~ || 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^ =^ A^1 B^1 +^ A^2 B^2 +^ · · ·^ +^ AnBn The dot product returns a single scalar value. θ = arccos( Aˆ · 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.

[

a 1 a 2 a 3

]

×

[

b 1 b 2 b 3

]

[

a 2 b 3 − a 3 b 2 a 3 b 1 − a 1 b 3 a 1 b 2 − a 2 b 1

]

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.

I 3 =

[

]

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 + f z 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 + 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 | = aM 1 − bM 2 + cM 3 − dM 4 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

]

M T^ =

[

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. 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: 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 =

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 =

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 = −(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, [email protected], Trinity College Dublin, Ireland. LATEX template from http://www.stdout.org/∼winston/latex/ Thanks Micha¨el, Amoss, and Veronica!