3Д БУМ

3Д принтеры и всё что с ними связано

Transforming a Vector by a Matrix

Often in computer graphics and game programming, you will need to use matrices to move vectors and points around onscreen, such as to move a point or piece of geometry to a new position. This process is called trans­formation. Matrices are used here for two reasons. First, they are excellent ways to store transformations as you saw previously, and second, they can easily be used to transform vectors and points by multiplication.

In order to transform a vector, you simply use the vector as a 3×1 or 4×1 matrix, depending on which type of matrix you are using to transform. This is important because if you try to multiply a 3×1 matrix with a 4×4 matrix, it will not work. The same goes for a 4×1 matrix being multiplies with a 3×3. Do not worry if your vector does not fill

the whole matrix, for instance a 3D vector being transformed by a 4×4 matrix. All you need to do is set the last element in the 4×1 matrix to 1. Then, after transformation, the last value can be discarded and you will once again have a vector with the same number of dimensions that you started with. Multiply your matrices together, and you will get a new, transformed, vector. This operation is shown in Figure 1.22.

1

2

3~

~3~

1×3+2×1+3×4

~17~

4

5

6

1

4 x 3 + 5 x1+6×4

41

7

8

9

4

7 x 3 + 8 x1+9×4

65

Figure 1.22 Transforming a vector by a matrix. Multiplying a vector by a matrix will yield a new vector with a new, transformed position. The operation is just regular matrix multiplication as defined earlier in the chapter, only this time it isn’t using two square matrices.

Для любых предложений по сайту: [email protected]