Guillaume,

This is the code that we use here. It was adapted from the algorithm
described in "The Matrix and Quaternion FAQ" (a good read).

Note that the results are in radians - use Math.toDegrees(...) to convert to
degrees.

Hope it works out for you - let me know if you have any problems or find any
bugs.

Best,

Daniel Selman
Tornado Labs Ltd.

Email:   [EMAIL PROTECTED]
Web:     http://www.tornadolabs.com
Phone:   +44 (0131) 343 2513
Fax:     +44 07070 800 483

=== code follows ===
                Matrix3d m1 = new Matrix3d();
                m_Transform3D.get( m1 );

                // extract the rotation angles from the upper 3x3 rotation
                // component of the 4x4 transformation matrix
            m_Rotation.y = -java.lang.Math.asin( m1.getElement( 2, 0 ) );
            double c = java.lang.Math.cos( m_Rotation.y );
                double tRx, tRy, tRz;

                if( java.lang.Math.abs( m_Rotation.y ) > 0.00001 )
                {
                        tRx = m1.getElement( 2, 2 ) / c;
                        tRy = -m1.getElement( 2, 1 )  / c;

                        m_Rotation.x = java.lang.Math.atan2( tRy, tRx );

                        tRx = m1.getElement( 0, 0 ) / c;
                        tRy = -m1.getElement( 1, 0 ) / c;

                        m_Rotation.z = java.lang.Math.atan2( tRy, tRx );
                }
                else
                {
                        m_Rotation.x  = 0.0;

                        tRx = m1.getElement( 1, 1 );
                        tRy = m1.getElement( 0, 1 );

                        m_Rotation.z = java.lang.Math.atan2( tRy, tRx );
                }

                m_Rotation.x = -m_Rotation.x;
                m_Rotation.z = -m_Rotation.z;

                // now try to ensure that the values are positive by adding 2PI if
necessary...
                if( m_Rotation.x < 0.0 )
                        m_Rotation.x += 2 * java.lang.Math.PI;

                if( m_Rotation.y < 0.0 )
                        m_Rotation.y += 2 * java.lang.Math.PI;

                if( m_Rotation.z < 0.0 )
                        m_Rotation.z += 2 * java.lang.Math.PI;



-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Guillaume
Bedard
Sent: 27 April 1999 22:27
To: [EMAIL PROTECTED]
Subject: [java3d] getRotation() from a Transform3D


I have yet another unresolved issue that is about getting the rotation
angle from a Transform3D object -- this has been previously discussed
on the mailing list but no working solution was found.

Is there a way to determine the exact rotation angles for each axes
from a given Transform3D?

Thanking you in advance,

Guillaume Bedard

Software Engineer
Adrenaline Software, Inc.
=====================================================================
To subscribe/unsubscribe, send mail to [EMAIL PROTECTED]
Java 3D Home Page: http://java.sun.com/products/java-media/3D/



=====================================================================
To subscribe/unsubscribe, send mail to [EMAIL PROTECTED]
Java 3D Home Page: http://java.sun.com/products/java-media/3D/

Reply via email to