i have object that are receiving 4 transformations step by step at different location in the software. We use a CAD engine library so i have custom objects to do transformation.
The Situation
i need to recuperate from the matrix of one of the object translation and rotation so that i can create a new matrix later one from those rotation.
The Code (sample)
// create a transformation object, very simple 1 translation and 3 rotations
var t = new Translation(10, 15, 20)
* new Rotation(10d.ToRadian(), Vector3D.AxisX)
* new Rotation(10d.ToRadian(), Vector3D.AxisY)
* new Rotation(10d.ToRadian(), Vector3D.AxisZ);
// convert to the windows Matrix3D
var m1 = ToWindowsMatrix(t);
// decompose the matrix to get one random possibility of combinaison of rotation x, y and Z to obtain the same result
var rx = Math.Atan2(m1.M32, m1.M33).ToDegree();
var ry = Math.Atan2(-m1.M31, Math.Sqrt(Math.Pow(m1.M32, 2) + Math.Pow(m1.M33, 2))).ToDegree();
var rz = Math.Atan2(m1.M21, m1.M11).ToDegree();
Source for formula to get rotation x,y and z:
// create a transformation object, in the same order, hardcoded translate but use the computed equivalent rotation x,y and z
var t2 = new Translation(10, 15, 20)
* new Rotation(rx.ToRadian(), Vector3D.AxisX)
* new Rotation(ry.ToRadian(), Vector3D.AxisY)
* new Rotation(rz.ToRadian(), Vector3D.AxisZ);
// convert to the windows Matrix3D
var m2 = ToWindowsMatrix(t2);
The Problem
if i take a 3d object and apply the transformation of t2 the rotation of the object is completely off compared to what t1 gives.
I absolutely need to get decomposed value as the whole system display the objects using 6 parameters (origin x,y,z and rotation x,y,z) which then create an identity matrix and apply a translate and 3 rotate.
I have been working of this for around 7 hours and i figured out that if i ONLY apply a single rotation on t1 ie "rotation X 90" and on t2 i still apply ALL rotations with the computed value the rotation DO match. So i have the feeling that the order of transformation need to be in a specific order but i cannot change it. So it mean i need to get the rotation x,y and z so that by applying Translate * RotX * RotY * RotZ it matches.
Anything i might have missed ? i have found some mathlab samples too but formula are all the same so far.