Hi all,

I do as is written in here:

http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm

but I get reversed angles in Softimage, and Maya.

Here is the code:

#####################################

import pymel.core as pm

dt = pm.dt

source = pm.polyCube()[0]

dest = pm.polyCube()[0]

source.translate.set( 2,0,0 )

source.rotate.set( 45,15,30 )

# get tranfromation matrix

transMat = dt.TransformationMatrix( pm.xform( source, q=True, matrix=True ) )

# get the rotation matrix from transformation matrix

rotMatrix = transMat.asRotateMatrix()

# here I try to convert rotation matrix to quaternion

# but it gives inverted rotations or completely wrong angles

qw = dt.sqrt( 1 + rotMatrix[0,0] + rotMatrix[1,1] + rotMatrix[2,2] ) / 2.0

qx = ( rotMatrix[2,1] - rotMatrix[1,2] ) / ( 4*qw )
qy = ( rotMatrix[0,2] - rotMatrix[2,0] ) / ( 4*qw )

qz = ( rotMatrix[1,0] - rotMatrix[0,1] ) / ( 4*qw )

qtrRot = dt.Quaternion( qx, qy, qz, qw )

rotEuler = dt.degrees( qtrRot.asEulerRotation() )

dest.rotate.set( rotEuler )

‘’’

# this returns rotations correctly but I want to create the quaternions myself.

rotEuler = dt.degrees( transMat.getRotation() )

dest.rotate.set( rotEuler )

‘’’

#####################################

The interesting thing is that, I did the same thing in XSI, ICE and it gives me inverted values too.

How can I found out how Maya really works. I read tranform parts of David Gould but it show how to use API.

My purpose it to find out how to create a quaternion and euler from an (axis, angle) rotation. ( without API, to learn 3d fundamentals )

Many thanks,