Open Inventor Release 2023.2.3
 
Loading...
Searching...
No Matches
SbRotation Class Reference

Class for representing a rotation. More...

#include <Inventor/SbRotation.h>

Public Member Functions

 SbRotation ()
 Default constructor.
 
 SbRotation (const float v[4])
 Constructor.
 
 SbRotation (float q0, float q1, float q2, float q3)
 Constructor.
 
 SbRotation (const SbMatrix &m)
 Constructor.
 
 SbRotation (const SbMatrix3 &m)
 Constructor.
 
 SbRotation (const SbVec3f &axis, float radians)
 Constructor.
 
 SbRotation (const SbVec3f &rotateFrom, const SbVec3f &rotateTo)
 Constructor.
 
const float * getValue () const
 Returns pointer to array of 4 components defining quaternion.
 
void getValue (float &q0, float &q1, float &q2, float &q3) const
 Returns 4 individual components of rotation quaternion.
 
void getValue (SbVec3f &axis, float &radians) const
 Returns corresponding 3D rotation axis vector and angle in radians.
 
void getValue (SbMatrix &matrix) const
 Returns corresponding 4x4 rotation matrix.
 
void getValue (SbMatrix3 &matrix) const
 Returns corresponding 3x3 rotation matrix.
 
void getValue (SbMatrixd &matrix) const
 Returns corresponding 4x4 rotation matrix.
 
SbRotationinvert ()
 Changes a rotation to be its inverse.
 
SbRotation inverse () const
 Returns the inverse of a rotation.
 
SbRotationsetValue (const float q[4])
 Sets value of rotation from array of 4 components of a quaternion.
 
SbRotationsetValue (float q0, float q1, float q2, float q3)
 Sets value of rotation from 4 individual components of a quaternion.
 
SbRotationsetValue (const SbMatrix &m)
 Sets value of rotation from a rotation matrix.
 
SbRotationsetValue (const SbMatrix3 &m)
 Sets rotation from a 3x3 rotation matrix.
 
SbRotationsetValue (const SbVec3f &axis, float radians)
 Sets value of vector from 3D rotation axis vector and angle in radians.
 
SbRotationsetValue (const SbVec3f &rotateFrom, const SbVec3f &rotateTo)
 Sets rotation to rotate one direction vector to another.
 
SbRotationsetValue (const SbRotationd &rotated)
 Sets rotation from a double precision rotation.
 
SbRotationsetValue (const SbMatrixd &md)
 Sets rotation from a double precision rotation matrix.
 
SbRotationoperator*= (const SbRotation &q)
 Multiplies by another rotation; results in product of rotations.
 
SbBool equals (const SbRotation &r, float tolerance) const
 Equality comparison within given tolerance - the square of the length of the maximum distance between the two quaternion vectors.
 
void multVec (const SbVec3f &src, SbVec3f &dst) const
 Multiplies the given vector by the matrix of this rotation.
 
void scaleAngle (float scaleFactor)
 Keep the axis the same.
 

Static Public Member Functions

static SbRotation slerp (const SbRotation &rot0, const SbRotation &rot1, float t)
 Spherical linear interpolation: as t goes from 0 to 1, returned value goes from rot0 to rot1.
 
static SbRotation identity ()
 Returns a null rotation.
 

Friends

int operator== (const SbRotation &q1, const SbRotation &q2)
 Equality comparison operator.
 
int operator!= (const SbRotation &q1, const SbRotation &q2)
 Inequality comparison operator.
 
SbRotation operator* (const SbRotation &q1, const SbRotation &q2)
 Multiplication of two rotations; results in product of rotations.
 

Detailed Description

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 rotation(0, 0, 1, 1.5707963f);
// This is the correct rotation.
SbRotation rotation( SbVec3f(0, 0, 1), 1.5707963f);
Class for representing a rotation.
Definition SbRotation.h:126
3D vector class.
Definition SbVec.h:932

SEE ALSO

SbRotationd, SbVec2d, SbVec2f, SbVec2i32, SbVec2s, SbVec3d, SbVec3f, SbVec3i32, SbVec3s, SbVec4b, SbVec4d, SbVec4f, SbVec4i32, SbVec4s, SbVec4ub, SbVec4ui32, SbVec4us

Definition at line 126 of file SbRotation.h.

Constructor & Destructor Documentation

◆ SbRotation() [1/7]

SbRotation::SbRotation ( )
inline

Default constructor.

The initial value is no rotation.

Definition at line 132 of file SbRotation.h.

◆ SbRotation() [2/7]

SbRotation::SbRotation ( const float  v[4])
inline

Constructor.

The quaternion constructor takes four floats that define a quaternion.
Note this is NOT the same as an axis/radian definition.

Definition at line 140 of file SbRotation.h.

◆ SbRotation() [3/7]

SbRotation::SbRotation ( float  q0,
float  q1,
float  q2,
float  q3 
)
inline

Constructor.

The quaternion constructor takes four floats that define a quaternion.
Note this is NOT the same as an axis/radian definition.

Definition at line 148 of file SbRotation.h.

◆ SbRotation() [4/7]

SbRotation::SbRotation ( const SbMatrix m)
inline

Constructor.

The matrix constructor takes a valid rotation matrix.

Definition at line 155 of file SbRotation.h.

◆ SbRotation() [5/7]

SbRotation::SbRotation ( const SbMatrix3 m)
inline

Constructor.

The matrix constructor takes a valid 3x3 rotation matrix.

Definition at line 162 of file SbRotation.h.

◆ SbRotation() [6/7]

SbRotation::SbRotation ( const SbVec3f axis,
float  radians 
)
inline

Constructor.

The axis/radians constructor creates a rotation of angle radians about the given axis.

Definition at line 169 of file SbRotation.h.

◆ SbRotation() [7/7]

SbRotation::SbRotation ( const SbVec3f rotateFrom,
const SbVec3f rotateTo 
)
inline

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.

Definition at line 178 of file SbRotation.h.

Member Function Documentation

◆ equals()

SbBool SbRotation::equals ( const SbRotation r,
float  tolerance 
) const

Equality comparison within given tolerance - the square of the length of the maximum distance between the two quaternion vectors.

◆ getValue() [1/6]

const float * SbRotation::getValue ( ) const
inline

Returns pointer to array of 4 components defining quaternion.

Definition at line 184 of file SbRotation.h.

◆ getValue() [2/6]

void SbRotation::getValue ( float &  q0,
float &  q1,
float &  q2,
float &  q3 
) const

Returns 4 individual components of rotation quaternion.

◆ getValue() [3/6]

void SbRotation::getValue ( SbMatrix matrix) const

Returns corresponding 4x4 rotation matrix.

◆ getValue() [4/6]

void SbRotation::getValue ( SbMatrix3 matrix) const

Returns corresponding 3x3 rotation matrix.

◆ getValue() [5/6]

void SbRotation::getValue ( SbMatrixd matrix) const

Returns corresponding 4x4 rotation matrix.

◆ getValue() [6/6]

void SbRotation::getValue ( SbVec3f axis,
float &  radians 
) const

Returns corresponding 3D rotation axis vector and angle in radians.

◆ identity()

static SbRotation SbRotation::identity ( )
inlinestatic

Returns a null rotation.

Definition at line 318 of file SbRotation.h.

◆ inverse()

SbRotation SbRotation::inverse ( ) const
inline

Returns the inverse of a rotation.

Definition at line 226 of file SbRotation.h.

◆ invert()

SbRotation & SbRotation::invert ( )

Changes a rotation to be its inverse.

◆ multVec()

void SbRotation::multVec ( const SbVec3f src,
SbVec3f dst 
) const

Multiplies the given vector by the matrix of this rotation.

◆ operator*=()

SbRotation & SbRotation::operator*= ( const SbRotation q)

Multiplies by another rotation; results in product of rotations.

◆ scaleAngle()

void SbRotation::scaleAngle ( float  scaleFactor)

Keep the axis the same.

Multiply the angle of rotation by the amount scaleFactor.

◆ setValue() [1/8]

SbRotation & SbRotation::setValue ( const float  q[4])

Sets value of rotation from array of 4 components of a quaternion.

◆ setValue() [2/8]

SbRotation & SbRotation::setValue ( const SbMatrix m)

Sets value of rotation from a rotation matrix.

◆ setValue() [3/8]

SbRotation & SbRotation::setValue ( const SbMatrix3 m)

Sets rotation from a 3x3 rotation matrix.

◆ setValue() [4/8]

SbRotation & SbRotation::setValue ( const SbMatrixd md)

Sets rotation from a double precision rotation matrix.

◆ setValue() [5/8]

SbRotation & SbRotation::setValue ( const SbRotationd rotated)

Sets rotation from a double precision rotation.

◆ setValue() [6/8]

SbRotation & SbRotation::setValue ( const SbVec3f axis,
float  radians 
)

Sets value of vector from 3D rotation axis vector and angle in radians.

◆ setValue() [7/8]

SbRotation & SbRotation::setValue ( const SbVec3f rotateFrom,
const SbVec3f rotateTo 
)

Sets rotation to rotate one direction vector to another.

The rotateFrom and rotateTo arguments are normalized before the rotation is calculated.

◆ setValue() [8/8]

SbRotation & SbRotation::setValue ( float  q0,
float  q1,
float  q2,
float  q3 
)

Sets value of rotation from 4 individual components of a quaternion.

◆ slerp()

static SbRotation SbRotation::slerp ( const SbRotation rot0,
const SbRotation rot1,
float  t 
)
static

Spherical linear interpolation: as t goes from 0 to 1, returned value goes from rot0 to rot1.

Friends And Related Symbol Documentation

◆ operator!=

int operator!= ( const SbRotation q1,
const SbRotation q2 
)
friend

Inequality comparison operator.

Definition at line 283 of file SbRotation.h.

◆ operator*

SbRotation operator* ( const SbRotation q1,
const SbRotation q2 
)
friend

Multiplication of two rotations; results in product of rotations.

◆ operator==

int operator== ( const SbRotation q1,
const SbRotation q2 
)
friend

Equality comparison operator.


The documentation for this class was generated from the following file: