public static Quaterniond fromRotationMatrix(Matrix3d matrix) {
    """
	Creates a new quaternion from the rotation matrix. The matrix will be interpreted as a rotation matrix even if it is not.
	
	@param matrix The rotation matrix
	@return The quaternion defined by the rotation matrix
    """
        final double trace = matrix.trace();
        if (trace < 0) {
            if (matrix.get(1, 1) > matrix.get(0, 0)) {
                if (matrix.get(2, 2) > matrix.get(1, 1)) {
                    final double r = (double) Math.sqrt(matrix.get(2, 2) - matrix.get(0, 0) - matrix.get(1, 1) + 1);
                    final double s = 0.5f / r;
                    return new Quaterniond(
                            (matrix.get(2, 0) + matrix.get(0, 2)) * s,
                            (matrix.get(1, 2) + matrix.get(2, 1)) * s,
                            0.5f * r,
                            (matrix.get(1, 0) - matrix.get(0, 1)) * s);
                } else {
                    final double r = (double) Math.sqrt(matrix.get(1, 1) - matrix.get(2, 2) - matrix.get(0, 0) + 1);
                    final double s = 0.5f / r;
                    return new Quaterniond(
                            (matrix.get(0, 1) + matrix.get(1, 0)) * s,
                            0.5f * r,
                            (matrix.get(1, 2) + matrix.get(2, 1)) * s,
                            (matrix.get(0, 2) - matrix.get(2, 0)) * s);
                }
            } else if (matrix.get(2, 2) > matrix.get(0, 0)) {
                final double r = (double) Math.sqrt(matrix.get(2, 2) - matrix.get(0, 0) - matrix.get(1, 1) + 1);
                final double s = 0.5f / r;
                return new Quaterniond(
                        (matrix.get(2, 0) + matrix.get(0, 2)) * s,
                        (matrix.get(1, 2) + matrix.get(2, 1)) * s,
                        0.5f * r,
                        (matrix.get(1, 0) - matrix.get(0, 1)) * s);
            } else {
                final double r = (double) Math.sqrt(matrix.get(0, 0) - matrix.get(1, 1) - matrix.get(2, 2) + 1);
                final double s = 0.5f / r;
                return new Quaterniond(
                        0.5f * r,
                        (matrix.get(0, 1) + matrix.get(1, 0)) * s,
                        (matrix.get(2, 0) - matrix.get(0, 2)) * s,
                        (matrix.get(2, 1) - matrix.get(1, 2)) * s);
            }
        } else {
            final double r = (double) Math.sqrt(trace + 1);
            final double s = 0.5f / r;
            return new Quaterniond(
                    (matrix.get(2, 1) - matrix.get(1, 2)) * s,
                    (matrix.get(0, 2) - matrix.get(2, 0)) * s,
                    (matrix.get(1, 0) - matrix.get(0, 1)) * s,
                    0.5f * r);
        }
    }
public static Quaterniond fromRotationMatrix(Matrix3d matrix) {
        final double trace = matrix.trace();
        if (trace < 0) {
            if (matrix.get(1, 1) > matrix.get(0, 0)) {
                if (matrix.get(2, 2) > matrix.get(1, 1)) {
                    final double r = (double) Math.sqrt(matrix.get(2, 2) - matrix.get(0, 0) - matrix.get(1, 1) + 1);
                    final double s = 0.5f / r;
                    return new Quaterniond(
                            (matrix.get(2, 0) + matrix.get(0, 2)) * s,
                            (matrix.get(1, 2) + matrix.get(2, 1)) * s,
                            0.5f * r,
                            (matrix.get(1, 0) - matrix.get(0, 1)) * s);
                } else {
                    final double r = (double) Math.sqrt(matrix.get(1, 1) - matrix.get(2, 2) - matrix.get(0, 0) + 1);
                    final double s = 0.5f / r;
                    return new Quaterniond(
                            (matrix.get(0, 1) + matrix.get(1, 0)) * s,
                            0.5f * r,
                            (matrix.get(1, 2) + matrix.get(2, 1)) * s,
                            (matrix.get(0, 2) - matrix.get(2, 0)) * s);
                }
            } else if (matrix.get(2, 2) > matrix.get(0, 0)) {
                final double r = (double) Math.sqrt(matrix.get(2, 2) - matrix.get(0, 0) - matrix.get(1, 1) + 1);
                final double s = 0.5f / r;
                return new Quaterniond(
                        (matrix.get(2, 0) + matrix.get(0, 2)) * s,
                        (matrix.get(1, 2) + matrix.get(2, 1)) * s,
                        0.5f * r,
                        (matrix.get(1, 0) - matrix.get(0, 1)) * s);
            } else {
                final double r = (double) Math.sqrt(matrix.get(0, 0) - matrix.get(1, 1) - matrix.get(2, 2) + 1);
                final double s = 0.5f / r;
                return new Quaterniond(
                        0.5f * r,
                        (matrix.get(0, 1) + matrix.get(1, 0)) * s,
                        (matrix.get(2, 0) - matrix.get(0, 2)) * s,
                        (matrix.get(2, 1) - matrix.get(1, 2)) * s);
            }
        } else {
            final double r = (double) Math.sqrt(trace + 1);
            final double s = 0.5f / r;
            return new Quaterniond(
                    (matrix.get(2, 1) - matrix.get(1, 2)) * s,
                    (matrix.get(0, 2) - matrix.get(2, 0)) * s,
                    (matrix.get(1, 0) - matrix.get(0, 1)) * s,
                    0.5f * r);
        }
    }
public static Quaterniond fromRotationMatrix ( Matrix3d matrix ) { final double trace = matrix . trace ( ) ; if ( trace < 0 ) { if ( matrix . get ( 1 , 1 ) > matrix . get ( 0 , 0 ) ) { if ( matrix . get ( 2 , 2 ) > matrix . get ( 1 , 1 ) ) { final double r = ( double ) Math . sqrt ( matrix . get ( 2 , 2 ) - matrix . get ( 0 , 0 ) - matrix . get ( 1 , 1 ) + 1 ) ; final double s = 0.5f / r ; return new Quaterniond ( ( matrix . get ( 2 , 0 ) + matrix . get ( 0 , 2 ) ) * s , ( matrix . get ( 1 , 2 ) + matrix . get ( 2 , 1 ) ) * s , 0.5f * r , ( matrix . get ( 1 , 0 ) - matrix . get ( 0 , 1 ) ) * s ) ; } else { final double r = ( double ) Math . sqrt ( matrix . get ( 1 , 1 ) - matrix . get ( 2 , 2 ) - matrix . get ( 0 , 0 ) + 1 ) ; final double s = 0.5f / r ; return new Quaterniond ( ( matrix . get ( 0 , 1 ) + matrix . get ( 1 , 0 ) ) * s , 0.5f * r , ( matrix . get ( 1 , 2 ) + matrix . get ( 2 , 1 ) ) * s , ( matrix . get ( 0 , 2 ) - matrix . get ( 2 , 0 ) ) * s ) ; } } else if ( matrix . get ( 2 , 2 ) > matrix . get ( 0 , 0 ) ) { final double r = ( double ) Math . sqrt ( matrix . get ( 2 , 2 ) - matrix . get ( 0 , 0 ) - matrix . get ( 1 , 1 ) + 1 ) ; final double s = 0.5f / r ; return new Quaterniond ( ( matrix . get ( 2 , 0 ) + matrix . get ( 0 , 2 ) ) * s , ( matrix . get ( 1 , 2 ) + matrix . get ( 2 , 1 ) ) * s , 0.5f * r , ( matrix . get ( 1 , 0 ) - matrix . get ( 0 , 1 ) ) * s ) ; } else { final double r = ( double ) Math . sqrt ( matrix . get ( 0 , 0 ) - matrix . get ( 1 , 1 ) - matrix . get ( 2 , 2 ) + 1 ) ; final double s = 0.5f / r ; return new Quaterniond ( 0.5f * r , ( matrix . get ( 0 , 1 ) + matrix . get ( 1 , 0 ) ) * s , ( matrix . get ( 2 , 0 ) - matrix . get ( 0 , 2 ) ) * s , ( matrix . get ( 2 , 1 ) - matrix . get ( 1 , 2 ) ) * s ) ; } } else { final double r = ( double ) Math . sqrt ( trace + 1 ) ; final double s = 0.5f / r ; return new Quaterniond ( ( matrix . get ( 2 , 1 ) - matrix . get ( 1 , 2 ) ) * s , ( matrix . get ( 0 , 2 ) - matrix . get ( 2 , 0 ) ) * s , ( matrix . get ( 1 , 0 ) - matrix . get ( 0 , 1 ) ) * s , 0.5f * r ) ; } }
Creates a new quaternion from the rotation matrix. The matrix will be interpreted as a rotation matrix even if it is not.

@param matrix The rotation matrix
@return The quaternion defined by the rotation matrix
Creates a new quaternion from the rotation matrix . The matrix will be interpreted as a rotation matrix even if it is not .