FbxQuaternion.ComposeSphericalXYZ() and FbxAMatrix.GetQ() give different results

FbxQuaternion.ComposeSphericalXYZ() and FbxAMatrix.GetQ() give different results

Anonymous
Not applicable
567 Views
1 Reply
Message 1 of 2

FbxQuaternion.ComposeSphericalXYZ() and FbxAMatrix.GetQ() give different results

Anonymous
Not applicable

For a given input quaternion, if I convert to Euler angles and then back again I sometimes get different answers depending on which method I use. 

 

For example, if I run the following code using the Python 2.7 SDK bindings:

import FbxCommon


quat_in = FbxCommon.FbxQuaternion( 0.10852469361474122, 0.10345202623008598, 0.988614142779236, 0.01273364997133784)

# Convert to Euler XYZ
euler = quat_in.DecomposeSphericalXYZ()

# Convert back to quat using ComposeSpherical()
quat_out_compose = FbxCommon.FbxQuaternion()
quat_out_compose.ComposeSphericalXYZ( euler )

# Convert back to quat using GetQ()
amat = FbxCommon.FbxAMatrix()
amat.SetR( euler )
quat_out_getq = amat.GetQ()


print("quat_in:          ", list(quat_in))
print("quat_out_compose: ", list(quat_out_compose))
print("quat_out_getq:    ", list(quat_out_getq))

 

I get this output:

('quat_in:          ', [0.10852469361474122, 0.10345202623008598, 0.988614142779236, 0.01273364997133784])
('quat_out_compose: ', [0.10852469361474362, 0.10345202623008602, 0.9886141427792358, 0.012733649971338119])
('quat_out_getq:    ', [0.13700585122690487, -0.0873827401610901, 0.9647038615115937, -0.20721996292864864])

 

Shouldn't these match? This is an issue for me because my files are being read by a program that uses GetQ() and the resulting animations are incorrect.

0 Likes
568 Views
1 Reply
Reply (1)
Message 2 of 2

regalir
Autodesk
Autodesk

Hi,

The "problem" with Euler angles is that they can be defined with multiple combinations, therefore, it cannot be guaranteed that in the conversion : Q -> Euler -> Matrix -> Q, the Matrix represent the actual rotation that the input quaternion does.  Some inputs will indeed resolve the above conversion to the same value.

For example:

 

Q=[0.3826834, 0, 0, 0.9238795] -> Euler=[45, 0, 0] -> Matrix=[ 1, 0.000, 0.000    -> Q=[0.3826834, 0, 0, 0.9238795]

                                                                                                                   0, 0.707, -0.707

                                                                                                                   0, 0.707,   0.707]

 

However, in the cases where the rotations cross the 90 or 180 degrees, the Rotation matrix will give an equivalent rotation.

 

This is what happens in your case:

Q=[0.10852469361474122, 0.10345202623008598, 0.988614142779236, 0.01273364997133784]

Euler=[166.61, -166.81, 25.9]

Matrix=[-0.876  -0.423,  0.228

                 0.375, -0.898, -0.225

                 0.300, -0.111,  0.947]

 

This matrix represent a rotation vector of [-13.384, -13.186, -154.199] (one equivalent solution to Euler) hence, getting the quaternion back from this matrix will give you a different value from the input one.

 

A quick search on the WEB, returned me this tool that helps to visualize Euler Angles and Rotation matrix:

http://danceswithcode.net/engineeringnotes/rotations_in_3d/demo3D/rotations_in_3d_tool.html

0 Likes