DirectX:Linear Transformation

Blog under Tag DirectX DirectX is mainly used for recording the learning process, the main reference "DirectX 12 3D games combat development." Data in this chapter is a review of linear algebra rhythm along DX12 Dragon Book of linear transformation.

Linear transformation

definition

There are many definitions of a linear transformation, where the reference book long, defined linear transformation given 3D graphics.
\ [\ Begin {aligned} & mathematical function \ is a linear transformation of tau if and only if: \\ & \ tau (\ vec {u} + \ vec {v}) = \ tau (\ vec {u}) + \ tau (\ vec {v}) \\ & \ tau (k \ vec {u}) = k \ tau (\ vec {u}) \ end {aligned} \]

Matrix representation

Linear transformation matrix is expressed.
\ [\ Begin {aligned} & provided \ vec u = (x, y , z), \ vec u may be written \ vec u = x \ vec i + y \ vec j + z \ vec k \\ & \ vec i, \ vec j, \ vec k to \ \\ vec u orthogonal base unit is located on the coordinate system so & \ vec u linear transformation \ of tau may be written \ tau (\ vec u) = x \ tau (\ vec i) + y \ tau ( \ vec j) + z \ tau (\ vec k) \\ & can be seen that this is a linear combination, can be represented as a matrix: \\ & \ tau (\ vec u) = x \ tau (\ vec i ) + y \ tau (\ vec j) + z \ tau (\ vec k) = [x, y, z] \ begin {bmatrix} \ tau (\ vec i) \\ \ tau (\ vec j) \\ \ tau (\ vec k) \ end {bmatrix} \ end {aligned} \]

Scaling

\ [\ Begin {aligned} & zoom is also a linear transformation. \\ & object scaling factor on the x, y, z axis are referred to as S_x, S_y, S_z, and scaling transformations as denoted S \\ & Obviously, S (\ vec i) = (S_x, 0,0), S (\ vec j) = (0, S_y, 0), S (\ vec k) = (0,0, S_z) \\ & then scaling matrix i.e. \ begin {bmatrix} S_x & 0 & 0 \\ 0 & S_y & 0 \\ 0 & 0 & S_z \ end {bmatrix} \\ & accordance with the nature of scaling transformation, we can easily obtain \\ & inverse conversion matrix corresponding to (i.e., scaling inverse matrix of the matrix) is \ begin {bmatrix} 1 / S_x & 0 & 0 \\ 0 & 1 / S_y & 0 \\ 0 & 0 & 1 / S_z \ end {bmatrix} \ end {aligned} \]

Rotation

Also a rotation linear transformation.
\ [\ Begin {aligned} & respect \ vec v about axis \ vec n clockwise rotation \ theta, \\ & For analytical purposes, the \ vec v is orthogonal to the orthogonal decomposition \ vec n partial \ vec v_ \ perp parallel to the \ vec n portions proj_ \ vec n (\ vec v) \\ & assumed \ vec n is a unit vector, then proj_ \ vec n (\ vec v) = ({\ vec n} \ dot {} \ vec v) \ vec n, \ vec v_ \ perp = \ vec v-proj_ \ vec n (\ vec v) \\ & rotation conversion referred to as R, will not change the apparent rotational operation proj_ \ vec n (\ vec v), so R_ \ vec n (\ vec v) = proj_ \ vec n (\ vec v) + R_ \ vec n (\ vec v_ \ perp) \\ & remember \ and angle vec v \ vec n is \ alpha, then | \ vec n \ times \ vec v | = | \ vec n || \ vec v | \ sin \ alpha = | \ vec v | \ sin \ alpha = | \ vec v_ \ perp | \\ & then R_ \ vec n (\ vec v_ \ perp) = \ vec v_ \ perp \ cos \ theta + (\ vec n \ times \ vec v) \ sin \ on theta \\ & mechanized, R_ \ vec n (\ vec v ) = proj_ \ vec n (\ vec v) + R_ \ vec n (\ vec v_ \ perp) \\ & = \ cos \ theta \ vec v + (1- \ cos \ theta) (\ vec n \ dot {} \ vec v) \ vec n + \ sin \ theta (\ vec n \ times \ vec v) \\ & put \ vec i into R to obtain R_ \ vec n (\ vec i) = (c + (1-c ) x ^ 2, (1-c) xy + sz, (1-c) xz-sy) \\ & Similarly available R_ \ vec n (\ vec j) and R_ \ vec n (\ vec k) \ \ &Then the rotation matrix is ​​\ begin {bmatrix} c + (1-c) x ^ 2 & (1-c) xy + sz & (1-c) xz-sy \\ (1-c) xy-sz & c + (1-c) y ^ 2 & (1-c) yz + sx \\ (1-c) xz + sy & (1-c) yz-sx & c + (1-c) z ^ 2 \ end {bmatrix} \\ & where, c = \ cos \ theta, s = \ sin \ theta \ end {aligned} \]
Rotation matrix is ​​an orthogonal matrix, i.e., any two row vectors in the matrix are mutually orthogonal, i.e. orthogonal matrix transpose inverse matrix. Thus we can efficiently obtain inverse transform matrix corresponding rotational transform.

Particularly, if the selected rotation about the axis, substituting the orthonormal basis can be obtained about the x, y, the rotation matrix corresponding to the z-axis:
\ [R_x = \ the begin {bmatrix}. 1 & 0 & 0 & 0 \\ 0 & \ COS \ Theta & \ SiN \ theta & 0 \\ 0 & - \ sin \ theta & \ cos \ theta & 0 \\ 0 & 0 & 0 & 1 \ end {bmatrix}, R_y = \ begin {bmatrix} \ cos \ theta & 0 & - \ sin \ theta & 0 \\ 0 & 1 & 0 & 0 \\ \ sin \ theta & 0 & \ cos \ theta & 0 \\ 0 & 0 &
0 & 1 \ end {bmatrix}, R_z = \ begin {bmatrix} \ cos \ theta & \ sin \ theta & 0 & 0 \\ - \ sin \ theta & \ cos \ theta & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \ end {bmatrix} \] where extending a multi-dimensional matrix in order to present a unified affine transformation.

Guess you like

Origin www.cnblogs.com/Li-F/p/11494786.html