Coin  4.0.3
Coin3D core library
Loading...
Searching...
No Matches
SbRotation Class Reference

The SbRotation class represents a rotation in 3D space. More...

#include <Inventor/SbRotation.h>

Public Member Functions

 SbRotation (const float q0, const float q1, const float q2, const float q3)
 
 SbRotation (const float q[4])
 
 SbRotation (const SbMatrix &m)
 
 SbRotation (const SbVec3f &axis, const float radians)
 
 SbRotation (const SbVec3f &rotateFrom, const SbVec3f &rotateTo)
 
 SbRotation (void)
 
SbBool equals (const SbRotation &r, float tolerance) const
 
SbBool fromString (const SbString &str)
 
void getValue (float &q0, float &q1, float &q2, float &q3) const
 
void getValue (SbMatrix &matrix) const
 
void getValue (SbVec3f &axis, float &radians) const
 
const float * getValue (void) const
 
SbRotation inverse (void) const
 
SbRotationinvert (void)
 
void multVec (const SbVec3f &src, SbVec3f &dst) const
 
SbRotationoperator*= (const float s)
 
SbRotationoperator*= (const SbRotation &q)
 
float operator[] (int n) const
 returns the n'th quaternion of this rotation
 
void print (FILE *fp) const
 
void scaleAngle (const float scaleFactor)
 
SbRotationsetValue (const float q0, const float q1, const float q2, const float q3)
 
SbRotationsetValue (const float q[4])
 
SbRotationsetValue (const SbMatrix &m)
 
SbRotationsetValue (const SbVec3f &axis, const float radians)
 
SbRotationsetValue (const SbVec3f &rotateFrom, const SbVec3f &rotateTo)
 
SbString toString () const
 

Static Public Member Functions

static SbRotation identity (void)
 
static SbRotation slerp (const SbRotation &rot0, const SbRotation &rot1, float t)
 

Related Symbols

(Note that these are not member symbols.)

int operator!= (const SbRotation &q1, const SbRotation &q2)
 
SbRotation operator* (const SbRotation &q1, const SbRotation &q2)
 
int operator== (const SbRotation &q1, const SbRotation &q2)
 
SbRotation slerp (const SbRotation &rot0, const SbRotation &rot1, float t)
 

Detailed Description

The SbRotation class represents a rotation in 3D space.

SbRotation is used extensively throughout the Coin library.

An SbRotation is stored internally as a quaternion for speed and storage reasons, but inquiries can be done to get and set axis and angle values for convenience.

Note that there is one very common mistake that is easy to make when setting the value of an SbRotation, and that is to inadvertently use the wrong SbRotation constructor. This example should clarify the problem:

SbRotation rotation(0, 0, 1, 1.5707963f);
The SbRotation class represents a rotation in 3D space.
Definition SbRotation.h:44

The programmer clearly tries to set a PI/2 rotation around the Z axis, but this will fail, as the SbRotation constructor invoked above is the one that takes as arguments the 4 floats of a quaternion. What the programmer almost certainly wanted to do was to use the SbRotation constructor that takes a rotation vector and a rotation angle, which is invoked like this:

SbRotation rotation(SbVec3f(0, 0, 1), 1.5707963f);
The SbVec3f class is a 3 dimensional vector with floating point coordinates.
Definition SbVec3f.h:51

Another common problem is to set the rotation value to exactly 0.0, while wanting to store just the information about a rotation angle: rotations are internally handled as quaternions, and when converting from an angle and a rotation value to a quaternion representation, the information about the angle "gets lost" if there is no actual rotation.

See also
SbMatrix

Constructor & Destructor Documentation

◆ SbRotation() [1/6]

SbRotation::SbRotation ( void )

The default constructor just initializes a valid rotation. The actual value is unspecified, and you should not depend on it.

◆ SbRotation() [2/6]

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

Construct a new SbRotation object initialized with the given axis-of-rotation and rotation angle.

◆ SbRotation() [3/6]

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

Construct a new SbRotation object initialized with the given quaternion components.

The array must be ordered as follows:

q[0] = x, q[1] = y, q[2] = z and q[3] = w, where the quaternion is specified by q = w + xi + yj + zk.

◆ SbRotation() [4/6]

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

Construct a new SbRotation object initialized with the given quaternion components.

◆ SbRotation() [5/6]

SbRotation::SbRotation ( const SbMatrix & m)

Construct a new SbRotation object initialized with the given rotation matrix.

◆ SbRotation() [6/6]

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

Construct a rotation which is the minimum rotation necessary to make vector rotateFrom point in the direction of vector rotateTo.

Example:

#include <Inventor/SbRotation.h>
#include <Inventor/SbVec3f.h>
#include <cstdio>
int
main(void)
{
SbVec3f from(10, 0, 0);
SbVec3f to(0, 10, 0);
SbRotation rot(from, to);
SbVec3f axis;
float angle;
rot.getValue(axis, angle);
axis.print(stdout);
printf(" angle==%f\n", angle);
return 0;
}
The SbList class is a template container class for lists.
Definition SbList.h:70
void print(FILE *fp) const
Definition SbVec3f.cpp:619

Member Function Documentation

◆ equals()

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

Check the internal quaternion representation vectors for equality within the given tolerance.

◆ fromString()

SbBool SbRotation::fromString ( const SbString & str)

Convert from a string representation, return whether this is a valid conversion

◆ getValue() [1/4]

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

Return the four quaternion components representing the rotation.

See also
setValue().

◆ getValue() [2/4]

void SbRotation::getValue ( SbMatrix & matrix) const

Return this rotation in the form of a matrix.

See also
setValue().

◆ getValue() [3/4]

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

Return the rotation in the form of an axis-of-rotation and a rotation angle.

See also
setValue().

◆ getValue() [4/4]

const float * SbRotation::getValue ( void ) const

Return pointer to an array with the rotation expressed as four quaternion values.

See also
setValue().

◆ identity()

SbRotation SbRotation::identity ( void )
static

Returns an identity rotation.

◆ inverse()

SbRotation SbRotation::inverse ( void ) const

Non-destructively inverses the rotation and returns the result.

See also
invert()

◆ invert()

SbRotation & SbRotation::invert ( void )

Invert the rotation. Returns reference to self.

See also
inverse()

◆ multVec()

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

Rotate the src vector and put the result in dst.

It is safe to let src and dst be the same SbVec3f instance.

◆ operator*=() [1/2]

SbRotation & SbRotation::operator*= ( const float s)

Multiplies components of quaternion with scalar value s. Returns reference to self.

◆ operator*=() [2/2]

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

Multiplies the quaternions.

Note that order is important when combining quaternions with the multiplication operator.

◆ print()

void SbRotation::print ( FILE * fp) const

Dump the state of this object to the fp file stream. Only works in debug version of library, method does nothing in an optimized build.

◆ scaleAngle()

void SbRotation::scaleAngle ( const float scaleFactor)

Scale the angle of rotation by scaleFactor.

◆ setValue() [1/5]

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

Set the rotation.

See also
getValue().

◆ setValue() [2/5]

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

Reset the rotation by the four quaternions in the array.

See also
getValue().

◆ setValue() [3/5]

SbRotation & SbRotation::setValue ( const SbMatrix & m)

Set the rotation from the components of the given matrix. Returns reference to self.

See also
getValue().

◆ setValue() [4/5]

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

Reset rotation with the given axis-of-rotation and rotation angle. Returns reference to self.

Make sure axis is not the null vector when calling this method.

See also
getValue().

◆ setValue() [5/5]

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

Construct a rotation which is the minimum rotation necessary to make vector rotateFrom point in the direction of vector rotateTo.

Returns reference to self.

See SbRotation constructor with corresponding input arguments for a simple code example.

See also
getValue().

◆ slerp()

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

Interpolates along the shortest path between the two rotation positions (from rot0 to rot1).

Returns the SbRotation which will rotate rot0 the given part t of the spherical distance towards rot1, where t=0 will yield rot0 and t=1 will yield rot1.

t should be in the interval [0, 1].

◆ toString()

SbString SbRotation::toString ( ) const

Return a string representation of this object

Friends And Related Symbol Documentation

◆ operator!=()

int operator!= ( const SbRotation & q1,
const SbRotation & q2 )
related

Check if the two rotations are not equal.

See also
equals().

◆ operator*()

SbRotation operator* ( const SbRotation & q1,
const SbRotation & q2 )
related

Multiplies the two rotations and returns the result.

Note that order is important when combining quaternions with the multiplication operator.

◆ operator==()

int operator== ( const SbRotation & q1,
const SbRotation & q2 )
related

Check if the two rotations are equal.

See also
equals().

◆ slerp()

SbRotation slerp ( const SbRotation & rot0,
const SbRotation & rot1,
float t )
related

Interpolates along the shortest path between the two rotation positions (from rot0 to rot1).

Returns the SbRotation which will rotate rot0 the given part t of the spherical distance towards rot1, where t=0 will yield rot0 and t=1 will yield rot1.

t should be in the interval [0, 1].


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