Chris,
I'm not sure I understand. What do you mean by 1 rotation? I have tested the
code by generating a 4x4 matrix for given x,y,z rotation angles and then
used the algorithm below to extract the original x,y and z angles (with a
small round-off error).
Daniel Selman
Tornado Labs Ltd.
Email: [EMAIL PROTECTED]
Web: http://www.tornadolabs.com
Phone: +44 (0131) 343 2513
Fax: +44 07070 800 483
-----Original Message-----
From: Christian Petermann [mailto:[EMAIL PROTECTED]]On Behalf Of
Christian Petermann
Sent: 02 May 1999 17:53
To: Daniel Selman
Cc: Guillaume Bedard; [EMAIL PROTECTED]
Subject: RE: [java3d] getRotation() from a Transform3D
Daniel,
In the code you sent, isn't your code assuming that there is only one
rotation?
Chris.
BTW do you have the internet address of that FAQ?
On Sat, 1 May 1999, Daniel Selman wrote:
> 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.
>
> === 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;
=====================================================================
To subscribe/unsubscribe, send mail to [EMAIL PROTECTED]
Java 3D Home Page: http://java.sun.com/products/java-media/3D/