Class SbRotationd


  • public class SbRotationd
    extends SbBasic
    Class for representing a rotation (double precision). Object that stores a rotation using double precision values. Although Open Inventor fields still store only single precision values, for certain applications it is useful and convenient to be able to store and manipulate double precision values, for example, double precision coordinate data or values that will be used for further computation.

    The rotation value is stored internally as a quaternion. Quaternion representation is more compact, faster to compute and more numerically stable than rotation matrices. Quaternion representation allows smooth rotation (spherical linear interpolation) and avoids the problem of "gimbal lock" associated with Euler angles. It is not necessary to deal directly with quaternions. Many convenience methods are provided to set and get rotations using matrix and axis/angle representations.

    Rotations are most commonly specified using an axis and an angle in radians. A common mistake is to use the constructor or setValue method that takes four double values, when intending to set an axis and angle. The methods that take four double values directly specify the quaternion value, which is probably not the intended result. For example:

     // Create a rotation of PI/2 radians around the Z axis:
     
     // Incorrect.
     // (Compiles, but actually sets the quaternion value directly!)
     SbRotationd rotation1 = new SbRotationd(0, 0, 1, 1.5707963);
     
     // This is the correct rotation.
     SbRotationd rotation2 = new SbRotationd(new SbVec3d(0, 0, 1), 1.5707963);

    See Also:
    SbRotation, SbVec2d, SbVec2f, SbVec2i32, SbVec2s, SbVec3d, SbVec3f, SbVec3i32, SbVec3s, SbVec4b, SbVec4d, SbVec4f, SbVec4i32, SbVec4s, SbVec4ub, SbVec4ui32, SbVec4us
    • Field Detail

      • array

        public final double[] array
    • Constructor Detail

      • SbRotationd

        public SbRotationd​(SbRotationd copyFrom)
      • SbRotationd

        public SbRotationd​(double[] components)
      • SbRotationd

        public SbRotationd​(double q0,
                           double q1,
                           double q2,
                           double q3)
        Constructor. The constructors that take four doubles create a quaternion from those doubles (careful, this differs from the four numbers in an axis/radian definition).
      • SbRotationd

        public SbRotationd()
        Constructor for rotation. The initial value is no rotation.
      • SbRotationd

        public SbRotationd​(SbMatrixd m)
        Constructor. The matrix constructor requires a valid rotation matrix.
      • SbRotationd

        public SbRotationd​(SbMatrix3 m)
        Constructor. The matrix constructor requires a valid 3x3 rotation matrix.
      • SbRotationd

        public SbRotationd​(SbVec3d axis,
                           double radians)
        Constructor. The axis/radians constructor creates a rotation of angle radians about the given axis.
      • SbRotationd

        public SbRotationd​(SbVec3d rotateFrom,
                           SbVec3d rotateTo)
        Constructor. The rotateFrom/To constructor defines rotation that rotates from one vector into another. The rotateFrom and rotateTo vectors are normalized by the constructor before calculating the rotation.
    • Method Detail

      • setValue

        public SbRotationd setValue​(double[] components)
      • getValue

        public double[] getValue()
      • setValue

        public SbRotationd setValue​(double[] components,
                                    int startIndex)
      • setValue

        public void setValue​(SbRotationd copyFrom)
      • scaleAngle

        public void scaleAngle​(double scaleFactor)
        Keep the axis the same. Multiply the angle of rotation by the amount scaleFactor.
      • multVec

        public SbVec3d multVec​(SbVec3d src)
        Multiplies the given vector by the matrix of this rotation.
      • times

        public SbRotationd times​(SbRotationd q2)
        Multiplication of two rotations; results in product of rotations.
      • identity

        public static SbRotationd identity()
        Returns a null rotation.
      • toArray

        public static SbRotationd[] toArray​(long nativeArray,
                                            long length)
      • setValue

        public SbRotationd setValue​(double q0,
                                    double q1,
                                    double q2,
                                    double q3)
        Sets value of rotation from 4 individual components of a quaternion.
      • slerp

        public static SbRotationd slerp​(SbRotationd rot0,
                                        SbRotationd rot1,
                                        double t)
        Spherical linear interpolation: as t goes from 0 to 1, returned value goes from rot0 to rot1.
      • getMatrixd

        public SbMatrixd getMatrixd()
        Returns corresponding 4x4 rotation matrix.
      • setValue

        public SbRotationd setValue​(SbVec3d axis,
                                    double radians)
        Sets value of vector from 3D rotation axis vector and angle in radians.
      • decompose

        public SbRotationd.AxisAngle decompose()
        Returns corresponding 3D rotation axis vector and angle in radians.
      • setValue

        public SbRotationd setValue​(SbVec3d rotateFrom,
                                    SbVec3d rotateTo)
        Sets rotation to rotate one direction vector to another. The rotateFrom and rotateTo arguments are normalized before the rotation is calculated.
      • getMatrix

        public SbMatrix getMatrix()
        Returns corresponding 4x4 rotation matrix.
      • invert

        public SbRotationd invert()
        Changes a rotation to be its inverse.
      • inverse

        public SbRotationd inverse()
        Returns the inverse of a rotation.
      • setValue

        public SbRotationd setValue​(SbMatrixd m)
        Sets value of rotation from a rotation matrix.
      • getMatrix3

        public SbMatrix3 getMatrix3()
        Returns corresponding 3x3 rotation matrix.
      • setValue

        public SbRotationd setValue​(SbRotation rotate)
        Sets rotation from a single precision rotation.
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • equals

        public boolean equals​(SbRotationd r,
                              double tolerance)
        Equality comparison within given tolerance - the square of the length of the maximum distance between the two quaternion vectors.
      • setValue

        public SbRotationd setValue​(SbMatrix m)
        Sets rotation from a single precision rotation matrix.
      • multiply

        public void multiply​(SbRotationd q)
        Multiplies by another rotation; results in product of rotations.