Class SbRotation


  • public class SbRotation
    extends SbBasic
    Class for representing a rotation. Object that stores a rotation. There are several ways to specify a rotation: quaternion (4 floats, in the order x, y, z, w), 4x4 rotation matrix, or axis and angle. All angles are in radians and all rotations are right-handed.

    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 float values, when intending to set an axis and angle. The methods that take four float 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!)
     SbRotation rotation1 = new SbRotation(0, 0, 1, 1.5707963f);
     
     // This is the correct rotation.
     SbRotation rotation2 = new SbRotation(new SbVec3f(0, 0, 1), 1.5707963f);

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

      • array

        public final float[] array
    • Constructor Detail

      • SbRotation

        public SbRotation​(SbRotation copyFrom)
      • SbRotation

        public SbRotation​(float[] components)
      • SbRotation

        public SbRotation​(float q0,
                          float q1,
                          float q2,
                          float q3)
        Constructor. The quaternion constructor takes four floats that define a quaternion.
        Note this is NOT the same as an axis/radian definition.
      • SbRotation

        public SbRotation()
        Default constructor. The initial value is no rotation.
      • SbRotation

        public SbRotation​(SbMatrix m)
        Constructor. The matrix constructor takes a valid rotation matrix.
      • SbRotation

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

        public SbRotation​(SbVec3f axis,
                          float radians)
        Constructor. The axis/radians constructor creates a rotation of angle radians about the given axis.
      • SbRotation

        public SbRotation​(SbVec3f rotateFrom,
                          SbVec3f rotateTo)
        Constructor. The rotateFrom/To constructor defines a 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 SbRotation setValue​(float[] components)
      • getValue

        public float[] getValue()
      • setValue

        public SbRotation setValue​(float[] components,
                                   int startIndex)
      • setValue

        public void setValue​(SbRotation copyFrom)
      • scaleAngle

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

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

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

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

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

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

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

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

        public SbRotation setValue​(SbMatrix3 m)
        Sets rotation from a 3x3 rotation matrix.
      • decompose

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

        public SbRotation setValue​(SbVec3f axis,
                                   float radians)
        Sets value of vector from 3D rotation axis vector and angle in radians.
      • getMatrix3

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

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

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

        public SbRotation setValue​(SbMatrix m)
        Sets value of rotation from a rotation matrix.
      • getMatrixd

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

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

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

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

        public SbRotation setValue​(SbMatrixd md)
        Sets rotation from a double precision rotation matrix.
      • setValue

        public SbRotation setValue​(SbRotationd rotated)
        Sets rotation from a double precision rotation.
      • multiply

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