36
Beginning Direct3D Game Programming: Mathematics 5 Matrix [email protected] Division of Digital Contents, DongSeo University. 15, May 2016

Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks

Embed Size (px)

Citation preview

Page 1: Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks

Beginning Direct3D Game Programming:Mathematics 5

[email protected]

Division of Digital Contents, DongSeo University.15, May 2016

Page 2: Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks

Linear system

2

A linear function is a polynomial function of degree zero or one, or is the zero polynomial(f(x)=0).

Page 3: Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks

Linear function When the function is of only one variable, it is of the

form

where a and b are constants, often real numbers. The graph of such a function of one variable is a nonver-

tical line. a is frequently referred to as the slope of the line, and b as the intercept.

For a function  of any finite number of independent variables, the general formula is

and the graph is a hyperplane of dimension k.

3

Page 4: Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks

Linear map In linear algebra, a linear function is a map f between

two vector spaces that preserves vector addition and scalar multiplication:

This tells us that for a some input, if we can decompose the input to addition, the result also be calculated sepa-rately.

In physics and other sciences, a nonlinear system, in contrast to a linear system, is a system which does not satisfy the above properties – meaning that the output of a nonlinear system is not directly proportional to the input.4

Page 5: Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks

Linear system A system of linear equations (or linear system) is a

collection of two or more linear equations involving the same set of variables.

Above is a system of three equations in the three vari-ables x, y, z.

5

Page 6: Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks

Plane A plane is a flat, two-dimensional surface that extends

infinitely far.

The equation of a plane with nonzero normal vector n=(a,b,c) through the point x0=(x0,y0,z0) is n·(x-x0)=0, where x=(x,y,z).

6

Page 7: Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks

Plugging in gives the general equation of a plane,ax+by+cz+d=0,

whered=-ax0-by0-cz0.

A plane specified in this form therefore has x-, y-, and z-intercepts atx = -d/ay = -d/bz = -d/c,

and lies at a distanceD=d/(sqrt(a2+b2+c2))

from the origin.

7

Page 8: Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks

Plane Point Distance

8

Page 9: Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks

9

Page 10: Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks

Linear system

A solution to a linear system is an assignment of numbers to the variables such that all the equations are simultaneously satisfied.

10

A linear system in three vari-ables determines a collection of planes. The intersection point is the solution.

Page 11: Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks

Matrix

Each element of a matrix is often denoted by a variable with two subscripts. For instance, a2,1 represents the el-ement at the second row and first column of a matrix A.

11

Page 12: Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks

A matrix (plural matrices) is a rectangular array of numbers, symbols, or expressions, arranged in rows and columns. The dimensions of below matrix are 2 × 3 (read "two by three"), because there are two rows and three columns.

12

Page 13: Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks

Size The size of a matrix is defined by the number of rows

and columns that it contains. A matrix with m rows and n columns is called an m × n matrix or m-by-n matrix, while m and n are called its dimensions.

13

Page 14: Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks

Notation Matrices are commonly written in box brackets or 

parentheses:

The (1,3) entry of the following matrix A is 5. It is de-noted a13, a1,3, A[1,3] or A1,3.

14

Page 15: Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks

Basic operations There are a number of basic operations that can be ap-

plied to modify matrices.– matrix addition– scalar multiplication– transposition– matrix multiplication– row operations.

15

Page 16: Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks

Addition The sum A+B of two m-by-n matrices A and Bis calcu-

lated entrywise: (A + B)i,j = Ai,j+ Bi,j, where 1 ≤ i ≤ m and 1 ≤ j ≤ n.

16

Page 17: Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks

Transposition The transpose of an m-by-n matrix A is the n-by-m ma-

trix AT formed by turning rows into columns and vice versa:

(AT)i,j = Aj,i

17

Page 18: Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks

Scalar multiplication The product cA of a number c (also called a scalar in the

parlance of abstract algebra) and a matrix A is com-puted by multiplying every entry of A by c:

(cA)i,j = c · Ai,j. This operation is called scalar multiplication.

– Its result is not named “scalar product” to avoid confusion, since “scalar product” is sometimes used as a synonym for “inner product”.

18

Page 19: Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks

Multiplication Multiplication of two matrices is defined if and only if the

number of columns of the left matrix is the same as the number of rows of the right matrix.

If A is an m-by-n matrix and B is an n-by-p matrix, then their matrix product AB is the m-by-p matrix whose en-tries are given by dot product of the corresponding row of A and the corresponding column of B:

19

Page 20: Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks

Schematic depiction of the matrix product AB of two matrices A and B.

20

Page 21: Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks

example

Matrix multiplication satisfies the rules (AB)C = A(BC) (associativity), and (A+B)C = AC+BC as well as C(A+B) =CA+CB (left and right distributivity), whenever the size of the matrices is such that the various products are defined. The product AB, they need not be equal, that is, generally

AB ≠ BA,21

3=2×0+3×1+4×0 2340=2×1000+3×100+4×10

Page 22: Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks

Identity element, Inverse element for multiplica-tion For some real number a a×1 = a In this case, 1 is called the identity element for multi-

plication.

a×( ) = 1 The answer to above equation is 1/a, 1/a is called the

inverse element of a for multiplication.

22

Page 23: Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks

Identity Matrix In linear algebra, the identity matrix, or sometimes

ambiguously called a unit matrix, of size n is the n × n square matrix with ones on the main diagonal and zeros elsewhere.

When A is m×n, it is a property of matrix multiplication that

23

Page 24: Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks

Determinant In linear algebra, the determinant is a useful value that

can be computed from the elements of a square matrix. The determinant of a matrix A is denoted det(A) or |A|.

24

Page 25: Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks

Linear Systems Matrices provide a compact and convenient way to rep-

resent systems of linear equations. For instance, the lin-ear system is given below.

Above linear system can be represented in matrix form like below.

25

Page 26: Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks

The matrix preceding the vector x, y, z of unknowns is called the coefficient matrix, and the column vector on the right side of the equals sign is called the con-stant vector. Linear systems for which the constant vector is nonzero (like the example above) are called non-homogeneous.

Linear systems for which every entry of the constant vector is zero are called homogeneous.– The geometric meaning of homogeneous is all the 3-planes

meet at the origin (0,0,0).26

Page 27: Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks

How to solve? We can set the augmented matrix formed by concate-

nating the coefficient matrix and constant vector.

And we may apply operations known as the Elementary Row Operation.

We will not examine that process.

27

Page 28: Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks

Homogeneous Matrix Later, we will use 4x4 matrices to consistently represent

translation, scaling and rotation in 3D space.

In that case a14, a24 and a34 is always zero, so we call this 4x4 matrix as a Homogeneous Matrix.

28

Page 29: Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks

Matrix Inverses An n × n matrix M is invertible if there exists a matrix,

which we denote by M−1, such that MM−1 =M−1M = I. The matrix M−1 is called the inverse of M.

Not every matrix has an inverse, and those that do not are called singular. An example of a singular matrix is any one that has a row or column consisting of all zeros.

Any matrix possessing a row that is a linear combination of the other rows of the matrix is singular.

29

Page 30: Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks

How to calculate the inverse of an n×n matrix M?

There is a well known algorithm called 'Gauss-Jordan elimination'.

We will not examine that algorithm.

30

Page 31: Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks

Back to the 2D Rotation Do you remember this linear system?

31

Page 32: Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks

x' = x·cos(θ) – y·sin(θ)y' = x·sin(θ) + x·cos(θ)

Above linear system can be represented like below.=

32

Page 33: Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks

Key observation In 2-dimensional space, when a position (a,b) is given, a

linear system uniquely determines a new position (a', b').

For example, for a position (2,1), We can find a linear system which transform to a new position (1,3).

33

Page 34: Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks

But there may be no linear system such like that, or may be very difficult to find the system.

In that case, the process may be decomposed to more easier steps.

To consistently represent this process, we uses matrix as a ADT(abstract data type).

34

Page 36: Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks