Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that...

105
Math for Games www.asyrani.com

Transcript of Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that...

Page 1: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Math for Gameswww.asyrani.com

Page 2: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Points and Vectors

Page 3: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Points and Cartesian Coordinates

Page 4: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

a point is a location in n-dimensional space. (In games, n is usually equal to 2 or 3.)

Page 5: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

The Cartesian coordinate system is by far themost common coordinate system employed by game programmers.

It uses two or three mutually perpendicular axes to specify a position in 2D or 3D space.

Page 6: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

So a point P is represented by a pair or triple of real numbers, (Px , Py) or (Px , Py , Pz).

Page 7: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Other Coordinates system?

Page 8: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Cylindrical coordinates . This system employs a vertical “height” axis h, a radial axis r emanating out from the vertical, and a yaw angle theta (θ).

Page 9: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

In cylindrical coordinates, a point P is represented by the triple of numbers (Ph , Pr , Pθ).

Page 10: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Spherical coordinates . This system employs a pitch angle phi (φ), a yaw angle theta (θ), and a radial measurement r.

Page 11: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Points are therefore representedby the triple of numbers (Pr , Pφ , Pθ).

Page 12: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

In Cartesian Coordinates system

Left-Handed Right-Handed

Page 13: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Most Frequently Used

Left-Handed

Page 14: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Vectors

Page 15: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Remember!!! Vector is not a point. It is a direction shows between two points or more

Page 16: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

A vector is a quantity that has both a magnitude and a direction in n-dimensional space.

A vector can be visualized as a directed line segment extending from a point called the tail to a point called the head.

Page 17: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

2D Vector

Page 18: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

A 3D vector can be represented by a triple of scalars (x, y, z)

Page 19: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

If the coordinates of A and B are: A(x1, y1, z1) and B(x2, y2, z2) the coordinates or components of the vector is

𝐴𝐵

Vector are the coordinates of the head minus the coordinates of the tail.

Page 20: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Where,

𝐴𝐵 = x2 − x1, y2 − y1, z2 − z1𝑜𝑟𝐵𝐴 = x1 − x2, y1 − y2, z1 − z2

A

B

𝑨𝑩

A

B

𝑩𝑨

Page 21: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Example: Calculate the components of the vectors that can be drawn in the triangle with vertices A(−3, 4, 0), B(3, 6, 3) and C(−1, 2, 1).

Page 22: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Any point or vector can be expressed as a sum of scalars (real numbers) multiplied by these unit basis vectors.

For example,(5, 3, –2) = 5i + 3j – 2k.

Page 23: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Vector Operations

Page 24: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Multiplication of a vector a by a scalar s is accomplished by multiplying theindividual components of a by s:

sa = ( s𝒂𝑥 , s𝒂𝑦, s𝒂𝑧)

Page 25: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Multiplication by a scalar has the effect of scaling the magnitude of the vector, while leaving its direction unchanged

Page 26: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Non-uniform scale

a scaling vector s is really just a compact way to represent a 3 × 3 diagonal scaling matrix S

The scale factor can be different along each axis

Page 27: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

𝑎𝑆 = 𝑎𝑥 𝑎𝑦 𝑎𝑧

𝑠𝑥 0 00 𝑠𝑦 0

0 0 𝑠𝑧

= 𝑠𝑥𝑎𝑥 𝑠𝑦𝑎𝑦 𝑠𝑧𝑎𝑧

Page 28: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Addition and Subtraction

Page 29: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees
Page 30: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

𝑎 + 𝑏 = [ 𝑎𝑥 + 𝑏𝑥 , 𝑎𝑦 + 𝑏𝑦 , 𝑎𝑧 + 𝑏𝑧 ]

Addition

Page 31: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

𝑎 + (−𝑏) = [ 𝑎𝑥 − 𝑏𝑥 , 𝑎𝑦 − 𝑏𝑦 , 𝑎𝑧 − 𝑏𝑧 ]

Subtraction (actually no subtraction in vector)

or

(−𝑎) + 𝑏 = [ −𝑎𝑥 + 𝑏𝑥 , −𝑎𝑦 + 𝑏𝑦 , −𝑎𝑧 + 𝑏𝑧 ]

Page 32: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Logically you can do this

direction + direction = direction

direction – direction = direction

point + direction = point

point – point = directionpoint + point = nonsense (don’t do it!)

Page 33: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Magnitude

The magnitude of a

vector is a scalar

representing the

length of the vector as

it would be measured in 2D or 3D space

Page 34: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

How to calculate magnitude

𝑎 = 𝑎𝑥2 + 𝑎𝑦

2 + 𝑎𝑧2

Page 35: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Application of vectors

Page 36: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

if we have the current position vector of an A.I. character P1, and a vector v representing her current velocity,

Then we can find her position on the next frame P2 by scaling the velocity vector by the frame time interval Δt, and then adding it to the current position.

Page 37: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

𝑃2 = 𝑃1 + ∆𝑡 𝑣

Page 38: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees
Page 39: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Steps to calculate sphere-sphere intersection

Step 1: Get vector 𝐶1 and 𝐶2 based on origin

𝐶1 = (𝑪𝟏𝒙, 𝑪𝟏𝒚

, 𝑪𝟏𝒛)

𝐶2 = (𝑪𝟐𝒙, 𝑪𝟐𝒚

, 𝑪𝟐𝒛)

Page 40: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Steps to calculate sphere-sphere intersection

Step 2: Get 𝐶1𝐶2 (𝐶2 − 𝐶1)

𝐶2 − 𝐶1 = (𝑪𝟐𝒙− 𝑪𝟏𝒙

, 𝑪𝟐𝒚− 𝑪𝟏𝒚

, 𝑪𝟐𝒛− 𝑪𝟏𝒛

)

Page 41: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Steps to calculate sphere-sphere intersection

Step 3: d = 𝐶2 − 𝐶1

𝑑 = (𝑑𝑥 , 𝑑𝑦 , 𝑑𝑧)

where𝑑𝑥 = 𝑪𝟐𝒙 − 𝑪𝟏𝒙

𝑑𝑦 = 𝑪𝟐𝒚 − 𝑪𝟏𝒚

𝑑𝑧 = 𝑪𝟐𝒛 − 𝑪𝟏𝒛

Page 42: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Steps to calculate sphere-sphere intersection

Step 4: 𝑑 (magnitude) for the length

𝑑 = 𝑑𝑥2 + 𝑑𝑦

2 + 𝑑𝑧2

Page 43: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

The magnitude of this vector d = |d| determines how far apart the spheres’ centers are.

If this distance is less than thesum of the spheres’ radii, they are intersecting; otherwise they’re not

Page 44: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Normalization and Unit Vectors

Page 45: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

A unit vector is a vector with a magnitude (length) of one.

Given an arbitrary vector v of length v = , we can convert it to a unit vector u that points in the same direction as v, but has unit length.

To do this, we simply multiply v by the reciprocal of its magnitude. We call this normalization:

Page 46: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

The formula

𝑢 =v

v=1

𝑣v

Page 47: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

A vector is said to be normal to a surface if it is perpendicular to that surface.

Normal vectors are highly useful in games and computer graphics. For example, a plane can be defined by a point and a normal vector.

And in 3D graphics, lighting calculations make heavy use of normal vectors to define the direction of surfaces relative to the direction of the light rays impinging upon them.

Page 48: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Dot/Cross Product and Projection

Page 49: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Two Types

the dot product (a.k.a. scalar product or inner product), and

the cross product (a.k.a. vector product or outer product).

Page 50: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

The dot product of two vectors yields a scalar; it is defined by adding the products of the individual components of the two vectors

a. b = 𝑎𝑥𝑏𝑥 + 𝑎𝑦𝑏𝑦 + 𝑎𝑧𝑏𝑧 = 𝑑

Page 51: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

The dot product can also be written as the product of the magnitudes of the two vectors and the cosine of the angle between them:

a. b = a b cos 𝜃 = 𝑑

Page 52: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

The dot product is commutative (i.e., the order of the two vectors can be reversed) and distributive over addition:

a. b = b. aa. b + c = a. b + a. c

Page 53: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

And the dot product combines with scalar multiplication as follows:

𝐬a. b = a. 𝐬b = 𝐬(a. b)

Page 54: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Vector Projection

Page 55: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

If u is a unit vector ( = 1), then the dot product (a ⋅ u) represents the length of the projection of vector a onto the infinite line defined by the direction of u

Page 56: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Magnitude as a Dot Product

Page 57: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

The squared magnitude of a vector can be found by taking the dot product of that vector with itself.

Its magnitude is then easily found by taking the square root:

Page 58: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

a 2 = a. aa = a. a

This works because the cosine of zero degrees is 1, so all that is left is

a a = a 2

Page 59: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Dot Product Test

Dot products are great for testing if two vectors are collinear or perpendicular, or whether they point in roughly the same or roughly opposite directions.

For any two arbitrary vectors a and b:

Page 60: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Collinear

Perpendicular

Collinear but opposite

Opposite DirectionSame direction

Page 61: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Cross Product

Page 62: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

The cross product (also known as the outer product or vector product) of two vectorsyields another vector that is perpendicular to the two vectors being multiplied

Page 63: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

a = 𝑎𝑥 , 𝑎𝑦, 𝑎𝑧b = (𝑏𝑥 , 𝑏𝑦, 𝑏𝑧)

Page 64: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

a × b

= 𝑎𝑦 𝑏𝑧 − 𝑏𝑦 𝑎𝑧 𝑖

− 𝑎𝑥 𝑏𝑧 − 𝑏𝑥 𝑎𝑧 𝑗

+ 𝑎𝑥 𝑏𝑦 − 𝑏𝑥 𝑎𝑦 𝑘

Page 65: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Magnitude of the Cross Product

Page 66: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

The magnitude of the cross product vector is the product of the magnitudes of the two vectors and the sine of the angle between them. (This is similar to the definition of the dot product, but it replaces the cosine with the sine.)

a × b = a b sin 𝜃 = 𝑑

Page 67: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

The magnitude of the cross product is equal to the area of the parallelogram whose sides are a and b

Page 68: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Since a triangle is one-half of a parallelogram, the area of a triangle whose vertices are specified by the position vectors V1 , V2 , and V3 can be calculated as one-half of themagnitude of the cross product of any two of its sides

𝐴𝑡𝑟𝑖𝑎𝑛𝑔𝑙𝑒 =1

2(𝑉2−𝑉1)×(𝑉3−𝑉1)

Page 69: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Properties of Cross Product

Page 70: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

a × b ≠ b × a

The cross product is not commutative

a × b = −b × a

However, it is anti-commutative

a × b + c = a × b + a × c

The cross product is distributive over addition:

Page 71: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

𝐬a × b = a × 𝒔b = 𝐬 a × b

And it combines with scalar multiplication as follows:

i × j = − j × i = k,j × k = − k × j = i,k × i = − i × k = j.

The Cartesian basis vectors are related by cross products as follows:

Page 72: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Cross products are also used in physics simulations. When a force is applied to an object, it will give rise to rotational motion if and only if it is applied off -center.

This rotational force is known as a torque , and it is calculated as follows.

Given a force F, and a vector r from the center of mass to the point at which the force is applied, the torque N = r × F.

Page 73: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

MATRICES

Page 74: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

A matrix is a rectangular array of m × n scalars. Matrices are a convenient way of representing linear transformations such as translation, rotation, and scale.

M=

𝑀11 𝑀12 𝑀13

𝑀21 𝑀22 𝑀23

𝑀31 𝑀32 𝑀33

Page 75: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Matrix Multiplication

Page 76: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

The product P of two matrices A and B is written P = AB.

If A and B are transformation matrices, then the product P is another transformation matrixthat performs both of the original transformations.

For example, if A is a scale matrix and B is a rotation, the matrix P would both scale and rotate the points or vectors to which it is applied.

Page 77: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Representing Points and Vectors as Matrices

Page 78: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Points and vectors can be represented as row matrices (1 × n) or column matrices (n × 1),

where n is the dimension of the space we’re working with (usually 2 or 3)

Page 79: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees
Page 80: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

v = 3, 4, −1

Can be written as:

v1 = [3 4 − 1]

or

v2 =34−1

= v1T

Page 81: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Identity Matrix

Page 82: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

The identity matrix is a matrix that, when multiplied by any other matrix, yields the very same matrix.

It is usually represented by the symbol I. Theidentity matrix is always a square matrix with 1’s along the diagonal and 0’s everywhere else

Page 83: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Matrix Inversion

Page 84: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

The inverse of a matrix A is another matrix (denoted A–1) that undoes the effects of matrix A.

So, for example, if A rotates objects by 37 degrees about the z-axis, then A–1 will rotate by –37 degrees about the z-axis.

Likewise, if A scales objects to be twice their original size, then A–1 scales objects to be half-sized. When a matrix is multiplied by its own inverse, the result is always the identity matrix

Page 85: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

𝑨(𝑨−1) ≡ (𝑨−1)𝑨 ≡ 𝑰

Not all matrices have inverses. However, all affine matrices (combinations of pure rotations, translations, scales, and shears) do have inverses.

Gaussian elimination or LU decomposition can be used to find the inverse, if one exists

Page 86: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

How to find an inverse matrix?

Page 87: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees
Page 88: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees
Page 89: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees
Page 90: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees
Page 91: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees
Page 92: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Transposition

Page 93: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Homogeneous Coordinates

Page 94: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

You may recall from high-school algebra that a 2 × 2 matrix can represent a rotation in two dimensions. To rotate a vector r through an angle of φ degrees (where positive rotations are counter-clockwise), we can write

𝑟𝑥′ 𝑟𝑦

′ = 𝑟𝑥 𝑟𝑦cos ∅ sin∅− sin∅ cos∅

Page 95: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees
Page 96: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

It’s probably no surprise that rotations in three dimensions can be represented by a 3 ×3 matrix. The two-dimensional example above is really just a three dimensionalrotation about the z-axis, so we can write

𝑟𝑥′ 𝑟𝑦

′ 𝑟𝑧′ = 𝑟𝑥 𝑟𝑦 𝑟𝑧

cos∅ sin∅ 0−sin∅ cos∅ 0

0 0 1

Page 97: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

The question naturally arises: Can a 3 × 3 matrix be used to represent translations? Sadly, the answer is no. The result of translating a point r by a translation t requires adding the components of t to the components of r individually:

r + t = (𝑟𝑥+t) (𝑟𝑦 + t) (𝑟𝑧 + t)

Page 98: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Coordinate Spaces

Page 99: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

In physics, a set of coordinate axes represents a frame of reference, so we sometimes refer to a set of axes as a coordinate frame (or just a frame).

People in the game industry also use the term coordinate space (or simply space) to refer to a set of coordinate axes. In the following sections, we’ll look at a few of the most common coordinate spaces used in games and computer graphics.

Page 100: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees
Page 101: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Model Space

Page 102: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

World Space

Page 103: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

View space (also known as camera space)

Page 104: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees
Page 105: Math for Games - WordPress.comThe inverse of a matrix A is another matrix (denoted A– 1) that undoes the effects of matrix A. So, for example, if A rotates objects by 37 degrees

Good Websites

http://www.codinglabs.net/article_world_view_projection_matrix