Class SbRotationd
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:
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConstructor for rotation.SbRotationd
(double[] components) SbRotationd
(double q0, double q1, double q2, double q3) Constructor.Constructor.Constructor.SbRotationd
(SbRotationd copyFrom) SbRotationd
(SbVec3d axis, double radians) Constructor.SbRotationd
(SbVec3d rotateFrom, SbVec3d rotateTo) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionReturns corresponding 3D rotation axis vector and angle in radians.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.boolean
Returns corresponding 4x4 rotation matrix.Returns corresponding 3x3 rotation matrix.Returns corresponding 4x4 rotation matrix.double[]
getValue()
static SbRotationd
identity()
Returns a null rotation.inverse()
Returns the inverse of a rotation.invert()
Changes a rotation to be its inverse.void
Multiplies by another rotation; results in product of rotations.Multiplies the given vector by the matrix of this rotation.void
scaleAngle
(double scaleFactor) Keep the axis the same.setValue
(double[] components) setValue
(double[] components, int startIndex) setValue
(double q0, double q1, double q2, double q3) Sets value of rotation from 4 individual components of a quaternion.Sets rotation from a single precision rotation matrix.Sets rotation from a 3x3 rotation matrix.Sets value of rotation from a rotation matrix.setValue
(SbRotation rotate) Sets rotation from a single precision rotation.void
setValue
(SbRotationd copyFrom) Sets value of vector from 3D rotation axis vector and angle in radians.Sets rotation to rotate one direction vector to another.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.times
(SbRotationd q2) Multiplication of two rotations; results in product of rotations.static SbRotationd[]
toArray
(long nativeArray, long length)
-
Field Details
-
array
public final double[] array
-
-
Constructor Details
-
SbRotationd
-
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
Constructor. The matrix constructor requires a valid rotation matrix. -
SbRotationd
Constructor. The matrix constructor requires a valid 3x3 rotation matrix. -
SbRotationd
Constructor. The axis/radians constructor creates a rotation of angle radians about the given axis. -
SbRotationd
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 Details
-
setValue
-
getValue
public double[] getValue() -
setValue
-
setValue
-
scaleAngle
public void scaleAngle(double scaleFactor) Keep the axis the same. Multiply the angle of rotation by the amount scaleFactor. -
multVec
Multiplies the given vector by the matrix of this rotation. -
times
Multiplication of two rotations; results in product of rotations. -
identity
Returns a null rotation. -
toArray
-
setValue
Sets value of rotation from 4 individual components of a quaternion. -
slerp
Spherical linear interpolation: as t goes from 0 to 1, returned value goes from rot0 to rot1. -
getMatrixd
Returns corresponding 4x4 rotation matrix. -
setValue
Sets value of vector from 3D rotation axis vector and angle in radians. -
decompose
Returns corresponding 3D rotation axis vector and angle in radians. -
setValue
Sets rotation to rotate one direction vector to another. The rotateFrom and rotateTo arguments are normalized before the rotation is calculated. -
getMatrix
Returns corresponding 4x4 rotation matrix. -
invert
Changes a rotation to be its inverse. -
inverse
Returns the inverse of a rotation. -
setValue
Sets value of rotation from a rotation matrix. -
getMatrix3
Returns corresponding 3x3 rotation matrix. -
setValue
Sets rotation from a single precision rotation. -
equals
-
equals
Equality comparison within given tolerance - the square of the length of the maximum distance between the two quaternion vectors. -
setValue
Sets rotation from a 3x3 rotation matrix. -
setValue
Sets rotation from a single precision rotation matrix. -
multiply
Multiplies by another rotation; results in product of rotations.
-