# Decompose matrix

This topic is 2430 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello,

1) When I have a rotation matrix R (that was build with several rotations: R = R1 * R2 * R3 ...), I can always extract the euler angles for x,y,z axis. Is this correct?

2) When I have a matrix M that is composed of scale, rotate and translate: M = S * R_x * R_y * R_z * T
Is it possible to extract the x,y,z euler angles, scalings and translation?

3) If I have an matrix M that is composed of an arbitrary number of transformations (scalings, rotations and translations). Is it always possible to build a new matrix N, that is composed of a scale matrix S, x,y,z rotation matrices R and a translation matrix T:
N = S * R_x * R_y * R_z * T

such that transforming a vector v with M yields the same is transforming it with N:
v' = v*M = v*N

In other words: Can I always disassemble a transformation Matrix M into a matrix that has the fixed chain S * R_x * R_y * R_z * T?

Thanks for any help!

##### Share on other sites

1) When I have a rotation matrix R (that was build with several rotations: R = R1 * R2 * R3 ...), I can always extract the euler angles for x,y,z axis. Is this correct?

Mostly correct, with the caveat that there are some rotations that have more than one representation as Euler angles. And you probably don't need to do this.

2) When I have a matrix M that is composed of scale, rotate and translate: M = S * R_x * R_y * R_z * T
Is it possible to extract the x,y,z euler angles, scalings and translation?[/quote]
Yes.

3) If I have an matrix M that is composed of an arbitrary number of transformations (scalings, rotations and translations). Is it always possible to build a new matrix N, that is composed of a scale matrix S, x,y,z rotation matrices R and a translation matrix T:
N = S * R_x * R_y * R_z * T

such that transforming a vector v with M yields the same is transforming it with N:
v' = v*M = v*N

In other words: Can I always disassemble a transformation Matrix M into a matrix that has the fixed chain S * R_x * R_y * R_z * T?[/quote]
It depends on what you mean by "scalings". If scalings are homotetic transformations (i.e., if you always scale all coordinates by the same number), yes. Otherwise, no.

##### Share on other sites

[quote name='schupf' timestamp='1334492239' post='4931411']
1) When I have a rotation matrix R (that was build with several rotations: R = R1 * R2 * R3 ...), I can always extract the euler angles for x,y,z axis. Is this correct?

Mostly correct, with the caveat that there are some rotations that have more than one representation as Euler angles. And you probably don't need to do this.
[/quote]
I think I have to do it in my case. I have an engine that only offers get/setTranslation(Vector3) and get/setRotation(Vector3). Now I want to ADD an additional rotation about an arbitrary axis.
So I get the rotation xyz angles from the object: Vec3 rot = obj->getRotation() and compute a rotation matrix R for the arbitary rotation:
R = createRotationMatrix(myAxis, myAngle);
Then I build a rotation Matrix objRot from rot and the final rotation matrix finalRot = objRot * R
Now I have to extract xyz Euler angles from finalRot to set the new euler angles at the object per obj->setRotation()

Would this be mathematically correct? Guess there is no other solution in my case?

##### Share on other sites
Are you sure get/setRotation(Vector3) refers to Euler angles? Euler angles are three numbers, but they are not a vector in any meaningful sense. However, 3D rotations can be described by a vector along the rotation axis whose length indicates how much to rotate.

##### Share on other sites
Yes, they are 3 euler angles, just packed together in a Vector3 (its not really a mathematical vector. more like a 3-tupel)

##### Share on other sites
So, you didn't ask the exact right question initially: You may not be able to recover the Euler angles you started with, but you can get Euler angles that represent the same rotation, which is actually what you need. Search the web for conversion matrix to euler'.

##### Share on other sites

So, you didn't ask the exact right question initially: You may not be able to recover the Euler angles you started with, but you can get Euler angles that represent the same rotation, which is actually what you need. Search the web for conversion matrix to euler'.

I never said I need the initial values. I just said I want to add a rotation to an already existing rotation (which is just available as euler angles). AFAIK the only way to do this is to build a rotation matrix (which is a matrix made of the euler angles & my rotation) and then extract the euler angles from this matrix and set these angles at the object.

##### Share on other sites
1) When I have a rotation matrix R (that was build with several rotations: R = R1 * R2 * R3 ...), I can always extract the euler angles for x,y,z axis. Is this correct?[/quote]
I thought R1, R2 and R3 were the axis rotations corresponding to the Euler angles.

##### Share on other sites
One more little question:
If I have code to extract the euler angles from a Rotation matrix R that is composed of a rotation around x, THEN y, then z:
R = R_x * R_y * R_z

then this code only works for exactly this order, doesn't it? If I have a rotation matrix that was made from 3 rotation matrices of order YXZ, then I have to use a different code to extract euler angles?

##### Share on other sites
Yes, matrix multiplication doesn't commute, so you need code specifically designed for the particular way you are composing the rotations around coordinate axes.

1. 1
2. 2
3. 3
4. 4
Rutin
13
5. 5

• 20
• 10
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633694
• Total Posts
3013364
×