Hi guys,

I’m having some rather basic but extremly important questions about the matrix multiplications in blender. Say I have a coordinate whose Vector representation is *v1* and I have a 3x3 rotation matrix *rotMat*, which one of the following is correct equation for applying the matrix to the vector:

- v2 = rotMat * v1
- v2 = v1 * rotMat

Furthermore, suppose I’ve resized v1 to 4D, and the matrix *mat* I have is now a 4x4 matrix, which one of the following is the correct equation for applying the matrix to the vector:

- v3 = mat * v1
- v3 = v1 * mat

Now, in my experience, in both cases the second equation, i.e. *vec * mat*, gives the correct results in blender. However, in most of the textbooks I’ve seen, the correct equation would be *mat * vec*.

To complicate things further, now I have three matrices, *rotX*, *rotY*, and *rotZ*, each representing a rotation around the X, Y, Z axises respectively. Now, if I wish to apply the rotations in the order of X->Y->Z to a vector *v*, which one of the following is correct?

- v4 = v * rotX * rotY * rotZ
- v4 = rotX * rotY * rotZ * v
- v4 = rotZ * rotY * rotX * v
- v4 = v * rotX.transpose() * rotY.transpose() * rotZ.transpose()
- v4 = rotX.transpose() * rotY.transpose() * rotZ.transpose() * v

In accordance with my previous blender experience, the first option should work – but it *does not*.

However, here is the confusion: **I’ve just found some java code that can take 2 vectors and produce all12 set of Euler/Cardan angles with different order of rotations**, e.g. XYZ, ZXY, ZYX, etc. This can be extremly useful for animating armature objects.

I’ve converted the core part of this code into python, but I’ve run into problem during the test phase. For each axis-only transformation matrix, the matrices produced by the java code is in fact the **transpose** of the same matrices produced by Blender.Mathutil.Euler().toMatrix(). For example, if I want to have a rotation matrix around the X-axis by 54.7 degrees, the code: Blender.Mathutils.Euler(angle, 0, 0).toMatrix() would generate the following matrix:

```
[1.000000, 0.000000, -0.000000](matrix [row 0])
[0.000000, 0.577350, 0.816497](matrix [row 1])
[0.000000, -0.816497, 0.577350](matrix [row 2])
```

However, the java code would generate the following matrix:

```
0.9999999999999998 0.0 -0.0
-0.0 0.5773502691896257 -0.8164965809277259
0.0 0.8164965809277259 0.5773502691896257
```

It’s obvious that the above two matrices are transpose of each other.

Now, this poses a problem: to carry out the rotation order of X->Y->Z, I thought I had to use the **first** equation in the last list, but the correct results is produced only with the **last** equation in the last list. I don’t know how this would affect how blender interpretes the final transformation matrix.

Thanks a lot for reading.

The original java code can be found at:

http://www.spaceroots.org/mantissa-doc/org/spaceroots/mantissa/geometry/Rotation.html

-D