Hi Vincent,

I've struggled with Euler angle problems before. I have a set of routines for 
converting. Check the computeYPRRotationMatrix() function below. If it produces the 
same rotation matrix as your sequence (which I think it will), then the other function 
will produce your Euler angles from the matrix.

josh

// Code snippets assume class data: yaw, pitch, roll in degrees

    /**
     * Computes the YPR rotation matrix:
     *
     * [cos(y)*cos(p)  cos(y)*sin(p)*sin(r)-sin(y)*cos(r)  
cos(y)*sin(p)*cos(r)+sin(y)*sin(r)]
     * [sin(y)*cos(p)  sin(y)*sin(p)*sin(r)+cos(y)*cos(r)  
sin(y)*sin(p)*cos(r)-cos(y)*sin(r)]
     * [-sin(p)        cos(p)*sin(r)                       cos(p)*cos(r)               
      ]
     */
    private void computeYPRRotationMatrix()
    {
        // precomputations
        double sp = Math.sin(Math.toRadians(pitch));
        double cp = Math.cos(Math.toRadians(pitch));
        double sy = Math.sin(Math.toRadians(yaw));
        double cy = Math.cos(Math.toRadians(yaw));
        double sr = Math.sin(Math.toRadians(roll));
        double cr = Math.cos(Math.toRadians(roll));

        // Create the matrix
        matrix =
                new Matrix3d(cy * cp, cy * sp * sr - sy * cr, cy * sp * cr + sy * sr,
                        sy * cp, sy * sp * sr + cy * cr, sy * sp * cr - cy * sr,
                        -sp, cp * sr, cp * cr);
    }

    /**
     * Computes the Euler (YPR order) angles from the <code>matrix</code>.
     *
     * Check element [2][0] of <code>matrix</code> for <code>rowFlag</code>.
     * Depending on the value of <code>rowFlag</code> the values of pitch, yaw
     * and roll are computed as follows:<BR>
     *
     * <code>rowFlag</code> = 1.0:<BR>
     * Y = atan2(-matrix[0][1], matrix[1][1]), P = -90.0, R = 0.0 <BR>
     * <BR>
     * <code>rowFlag</code> = -1.0:<BR>
     * Y = atan2(matrix[0][1], matrix[1][1]), P = 90.0, R = 0.0 <BR>
     * <BR>
     * otherwise:<BR>
     * Y = atan2(matrix[1][0], matrix[0][0]), P = asin(-matrix[2][0]),
     * R = atan2(matrix[2][1], matrix[2][2]) <BR>
     */
    private void computeEulerYPRAngles()
    {
        int rowFlag = (int) matrix.m20;
        switch (rowFlag) {
        case 1:
            yaw = Math.toDegrees(Math.atan2(-matrix.m01, matrix.m11));
            pitch = -90.0;
            roll = 0.0;
            break;
        case -1:
            yaw = Math.toDegrees(Math.atan2(-matrix.m01, matrix.m11));
            pitch = 90.0;
            roll = 0.0;
            break;
        default:
            yaw = Math.toDegrees(Math.atan2(matrix.m10, matrix.m00));
            pitch = Math.toDegrees(Math.asin(-matrix.m20));
            roll = Math.toDegrees(Math.atan2(matrix.m21, matrix.m22));
            break;
        }
    }



>>> Vincent St-Amour <[EMAIL PROTECTED]> 07/11/02 09:51AM >>>


Hello,

    I build a rotation matrix from the 3 rotation angles ( Rotation
around X axis, rotation around Y axis and rotation around Z axis).

    I want to know if it is possible to retreive those angle from a
rotation matrix ( the other way arround ) ?

    Thank you all,

    Vincent St-Amour
    Montreal.


    Here is how I build my matrix from the 3 rotation angles :

                                       //-
                              -------

                              Matrix4d
                              lRotX = new
                              Matrix4d();

                              lRotX.setIdentity();


                              lRotX.rotX(
                              (float)
                              Math.toRadians(
                              X_Angle_Value
                              ) );
                                      //-
                              -------

                              Matrix4d
                              lRotY = new
                              Matrix4d();

                              lRotY.setIdentity();


                              lRotY.rotY(
                              (float)
                              Math.toRadians(
                              Y_Angle_Value
                              ) );
                                      //-
                              -------

                              Matrix4d
                              lRotZ = new
                              Matrix4d();

                              lRotZ.setIdentity();


                              lRotZ.rotZ(
                              (float)
                              Math.toRadians(
                              Z_Angle_Value
                              ) );
                                      //-
                              -------

                              Matrix4d
                              lResult =
                              new
                              Matrix4d();

                              lResult.setIdentity();


                              lResult.mul(
                              lRotX );

                              lResult.mul(
                              lRotY );

                              lResult.mul(
                              lRotZ );

==========================================================================To 
unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to