Thinking: matrix and transformation, and the use of matrix in DirectX and OpenGL: Left multiplication/right multiplication, row precedence/column precedence ,...

Source: Internet
Author: User
Thinking: matrix and transformation, and the application of matrix in DirectX and OpenGL

1. Matrix and linear transformation: one-to-one correspondence

A matrix is a tool used to represent linear transformations. It corresponds to linear transformations one by one.
Consider linear transformation:
A11 * x1 + a12 * x2 +... + a1n * xn = x1'
A21 * x1 + a22 * x2 +... + a2n * xn = x2'
...
Am1 * x1 + am2 * x2 +... + amn * xn = xm'

Correspondingly, the matrix representation is:
| A11 a12... a1n | x1 | x1' |
| A21 a22... a2n | x2 | x2 '|
|... | * |... | = |... |
| Am1 am2... amn | xn | xm '|

It can also be shown below:
| A11 a21... am1 |
| A12 a22... am2 |
| X1 x2.... xn | * |... | = | x1 'x2 '... xm' |
| A1n a2n... amn |

Six matrices are involved. They are A [m * n], X [n * 1], x' [m * 1], X [1 * n], A [n * m], x' [1 * m].
It can be understood as vector x (x1, x2 ,..., xn) after A transformation matrix A [m * n] or A [n * m], it becomes another vector x' (x1 ', x2 ',..., xm ')).

2. Matrix Representation: row matrix vs. column matrix

The names of row and column matrices are derived self-vectors and column vectors.
In fact, matrix A [m * n] can be regarded as A row matrix consisting of m n-dimensional row vectors, or A column matrix consisting of n m-dimensional column vectors.
X [n * 1]/X' [m * 1] is equivalent to one column vector in n/m dimensions. X [1 * n]/X' [1 * m] is equivalent to a row vector in n/m dimensions.
Row matrix and Column matrix are only two different representations. The former indicates that a vector is mapped to a Row of the matrix, and the latter indicates that a vector is mapped to a Column of the matrix.
Essentially, it represents the same linear transformation. Matrix Operations stipulate that they can change the ing relationship through transpose operations.

3. The order of multiplication of the matrix: premultiplication or left multiplication vs. postmultiplication or right Multiplication

Note that two different representations correspond to different operation sequence:
If a column vector is transformed, the transformation matrix (row matrix/vectors) must appear on the left of the multiplication number, that is, pre-multiply, also known as premultiplication or left multiplication.
If a row vector is transformed, the transformation matrix (column matrix/vectors) must appear on the right side of the multiplication number, that is, post-multiply, which is also called post multiplication or right multiplication.
Generally, it is not wrong, because the matrix multiplication property determines that a matrix with the same inner dimension can be multiplied. Why is this rule? Why do we need to multiply row vector by column vector or column vector by row vector ??? Think about it...

Therefore, left multiplication or right multiplication is related to the representation of the transformed vector, rather than the storage order.

4. Storage order of the matrix: store by row first vs. Store by column first

When using a matrix in a computer, the storage matrix is first encountered.
Because the computer storage space is sequential, how to store m * n elements of A [m * n] is A problem. There are generally two types: store by row first and store by column first.

Row-major: the sequence of saving data to a11, a12,..., and amn.
Column-major: the sequence of saving data to a11, a21,..., and amn.

The problem is that you have a set of stored matrix elements. You do not know how to read elements to form a matrix. For example, you do not know how many columns a12 should be placed in.
Therefore, each system has its own rules. For example, if the rules are stored, they are read by the rules. DX uses Row-major and OGL uses Column-major. that is to say, the storage sequence of the same matrix A [m * n] In DX and OGL is different, which causes the trouble of Inter-System Conversion.

However, in DX, vertices/Vectors are represented by Row Vectors, so the corresponding transformation Matrix is Column Matrix/Vectors, while in OGL, point/Vector is represented by Column Vector, so the corresponding transformation Matrix is Row Matrix/Vectors. therefore, if a vector x (x1, x2, x3, 1) or point (x (x1, x2, x3, 1) is specified in DX )) apply the matrix transformation of A [4*4], that is, x' = x (x1, x2, x3, 1) * A [4*4, so its storage sequence is a11, a12 ,..., a43, a44. In OGL, perform the same vector or point transformation because it uses Row Matrix/Vectors, the transformation matrix of its application should be a' [4*4] = A [4*4] ('indicates Transpose/Transpose ), that is, x' = A' [4*4] * x' (x1, x2, x3, 1). However, because Column-major is used, its storage sequence is exactly a11, a12 ,..., a43, a44 !!!
In fact, for DX and OGL, the same transformation stores the same matrix element sequence. for example, the 15 elements in the 13th, 14th contain deltaZ, deltaY, and deltaZ.

Refs:

Http://mathworld.wolfram.com/Matrix.html

Http://www.gamedev.net/community/forums/topic.asp? Topic_id = 321862

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.