Open CASCADE Technology Reference Manual 8.0.0
Loading...
Searching...
No Matches
Public Member Functions
gp_Quaternion Class Reference

Represents operation of rotation in 3d space as quaternion and implements operations with rotations basing on quaternion mathematics. More...

#include <gp_Quaternion.hxx>

Public Member Functions

constexpr gp_Quaternion () noexcept
 Creates an identity quaternion.
 
constexpr gp_Quaternion (const double theX, const double theY, const double theZ, const double theW) noexcept
 Creates quaternion directly from component values.
 
 gp_Quaternion (const gp_Vec &theVecFrom, const gp_Vec &theVecTo)
 Creates quaternion representing shortest-arc rotation operator producing vector theVecTo from vector theVecFrom.
 
 gp_Quaternion (const gp_Vec &theVecFrom, const gp_Vec &theVecTo, const gp_Vec &theHelpCrossVec)
 Creates quaternion representing shortest-arc rotation operator producing vector theVecTo from vector theVecFrom. Additional vector theHelpCrossVec defines preferred direction for rotation and is used when theVecTo and theVecFrom are directed oppositely.
 
 gp_Quaternion (const gp_Vec &theAxis, const double theAngle)
 Creates quaternion representing rotation on angle theAngle around vector theAxis.
 
 gp_Quaternion (const gp_Mat &theMat)
 Creates quaternion from rotation matrix 3*3 (which should be orthonormal skew-symmetric matrix)
 
bool IsEqual (const gp_Quaternion &theOther) const
 Simple equal test without precision.
 
void SetRotation (const gp_Vec &theVecFrom, const gp_Vec &theVecTo)
 Sets quaternion to shortest-arc rotation producing vector theVecTo from vector theVecFrom. If vectors theVecFrom and theVecTo are opposite then rotation axis is computed as theVecFrom ^ (1,0,0) or theVecFrom ^ (0,0,1).
 
void SetRotation (const gp_Vec &theVecFrom, const gp_Vec &theVecTo, const gp_Vec &theHelpCrossVec)
 Sets quaternion to shortest-arc rotation producing vector theVecTo from vector theVecFrom. If vectors theVecFrom and theVecTo are opposite then rotation axis is computed as theVecFrom ^ theHelpCrossVec.
 
void SetVectorAndAngle (const gp_Vec &theAxis, const double theAngle)
 Create a unit quaternion from Axis+Angle representation.
 
void GetVectorAndAngle (gp_Vec &theAxis, double &theAngle) const
 Convert a quaternion to Axis+Angle representation, preserve the axis direction and angle from -PI to +PI.
 
void SetMatrix (const gp_Mat &theMat)
 Create a unit quaternion by rotation matrix matrix must contain only rotation (not scale or shear)
 
gp_Mat GetMatrix () const
 Returns rotation operation as 3*3 matrix.
 
void SetEulerAngles (const gp_EulerSequence theOrder, const double theAlpha, const double theBeta, const double theGamma)
 Create a unit quaternion representing rotation defined by generalized Euler angles.
 
void GetEulerAngles (const gp_EulerSequence theOrder, double &theAlpha, double &theBeta, double &theGamma) const
 Returns Euler angles describing current rotation.
 
constexpr void Set (const double theX, const double theY, const double theZ, const double theW) noexcept
 
constexpr void Set (const gp_Quaternion &theQuaternion) noexcept
 
constexpr double X () const noexcept
 
constexpr double Y () const noexcept
 
constexpr double Z () const noexcept
 
constexpr double W () const noexcept
 
constexpr void SetIdent () noexcept
 Make identity quaternion (zero-rotation)
 
constexpr void Reverse () noexcept
 Reverse direction of rotation (conjugate quaternion)
 
constexpr gp_Quaternion Reversed () const noexcept
 Return rotation with reversed direction (conjugated quaternion)
 
constexpr void Invert ()
 Inverts quaternion (both rotation direction and norm)
 
constexpr gp_Quaternion Inverted () const
 Return inversed quaternion q^-1.
 
constexpr double SquareNorm () const noexcept
 Returns square norm of quaternion.
 
double Norm () const
 Returns norm of quaternion.
 
constexpr void Scale (const double theScale) noexcept
 Scale all components by quaternion by theScale; note that rotation is not changed by this operation (except 0-scaling)
 
void operator*= (const double theScale)
 
constexpr gp_Quaternion Scaled (const double theScale) const noexcept
 Returns scaled quaternion.
 
constexpr gp_Quaternion operator* (const double theScale) const noexcept
 
void StabilizeLength ()
 Stabilize quaternion length within 1 - 1/4. This operation is a lot faster than normalization and preserve length goes to 0 or infinity.
 
void Normalize ()
 Scale quaternion that its norm goes to 1. The appearing of 0 magnitude or near is a error, so we can be sure that can divide by magnitude.
 
gp_Quaternion Normalized () const
 Returns quaternion scaled so that its norm goes to 1.
 
constexpr gp_Quaternion Negated () const noexcept
 Returns quaternion with all components negated. Note that this operation does not affect neither rotation operator defined by quaternion nor its norm.
 
constexpr gp_Quaternion operator- () const noexcept
 
constexpr gp_Quaternion Added (const gp_Quaternion &theOther) const noexcept
 Makes sum of quaternion components; result is "rotations mix".
 
constexpr gp_Quaternion operator+ (const gp_Quaternion &theOther) const noexcept
 
constexpr gp_Quaternion Subtracted (const gp_Quaternion &theOther) const noexcept
 Makes difference of quaternion components; result is "rotations mix".
 
constexpr gp_Quaternion operator- (const gp_Quaternion &theOther) const noexcept
 
constexpr gp_Quaternion Multiplied (const gp_Quaternion &theOther) const noexcept
 Multiply function - work the same as Matrices multiplying.
 
constexpr gp_Quaternion operator* (const gp_Quaternion &theOther) const noexcept
 
constexpr void Add (const gp_Quaternion &theOther) noexcept
 Adds components of other quaternion; result is "rotations mix".
 
void operator+= (const gp_Quaternion &theOther)
 
constexpr void Subtract (const gp_Quaternion &theOther) noexcept
 Subtracts components of other quaternion; result is "rotations mix".
 
void operator-= (const gp_Quaternion &theOther)
 
void Multiply (const gp_Quaternion &theOther)
 Adds rotation by multiplication.
 
void operator*= (const gp_Quaternion &theOther)
 
constexpr double Dot (const gp_Quaternion &theOther) const noexcept
 Computes inner product / scalar product / Dot.
 
double GetRotationAngle () const
 Return rotation angle from -PI to PI.
 
gp_Vec Multiply (const gp_Vec &theVec) const
 Rotates vector by quaternion as rotation operator.
 
gp_Vec operator* (const gp_Vec &theVec) const
 

Detailed Description

Represents operation of rotation in 3d space as quaternion and implements operations with rotations basing on quaternion mathematics.

In addition, provides methods for conversion to and from other representations of rotation (3*3 matrix, vector and angle, Euler angles)

Constructor & Destructor Documentation

◆ gp_Quaternion() [1/6]

constexpr gp_Quaternion::gp_Quaternion ( )
inlineconstexprnoexcept

Creates an identity quaternion.

◆ gp_Quaternion() [2/6]

constexpr gp_Quaternion::gp_Quaternion ( const double theX,
const double theY,
const double theZ,
const double theW )
inlineconstexprnoexcept

Creates quaternion directly from component values.

◆ gp_Quaternion() [3/6]

gp_Quaternion::gp_Quaternion ( const gp_Vec & theVecFrom,
const gp_Vec & theVecTo )
inline

Creates quaternion representing shortest-arc rotation operator producing vector theVecTo from vector theVecFrom.

◆ gp_Quaternion() [4/6]

gp_Quaternion::gp_Quaternion ( const gp_Vec & theVecFrom,
const gp_Vec & theVecTo,
const gp_Vec & theHelpCrossVec )
inline

Creates quaternion representing shortest-arc rotation operator producing vector theVecTo from vector theVecFrom. Additional vector theHelpCrossVec defines preferred direction for rotation and is used when theVecTo and theVecFrom are directed oppositely.

◆ gp_Quaternion() [5/6]

gp_Quaternion::gp_Quaternion ( const gp_Vec & theAxis,
const double theAngle )
inline

Creates quaternion representing rotation on angle theAngle around vector theAxis.

◆ gp_Quaternion() [6/6]

gp_Quaternion::gp_Quaternion ( const gp_Mat & theMat)
inline

Creates quaternion from rotation matrix 3*3 (which should be orthonormal skew-symmetric matrix)

Member Function Documentation

◆ Add()

constexpr void gp_Quaternion::Add ( const gp_Quaternion & theOther)
inlineconstexprnoexcept

Adds components of other quaternion; result is "rotations mix".

◆ Added()

constexpr gp_Quaternion gp_Quaternion::Added ( const gp_Quaternion & theOther) const
inlineconstexprnoexcept

Makes sum of quaternion components; result is "rotations mix".

◆ Dot()

constexpr double gp_Quaternion::Dot ( const gp_Quaternion & theOther) const
inlineconstexprnoexcept

Computes inner product / scalar product / Dot.

◆ GetEulerAngles()

void gp_Quaternion::GetEulerAngles ( const gp_EulerSequence theOrder,
double & theAlpha,
double & theBeta,
double & theGamma ) const

Returns Euler angles describing current rotation.

◆ GetMatrix()

gp_Mat gp_Quaternion::GetMatrix ( ) const

Returns rotation operation as 3*3 matrix.

◆ GetRotationAngle()

double gp_Quaternion::GetRotationAngle ( ) const

Return rotation angle from -PI to PI.

◆ GetVectorAndAngle()

void gp_Quaternion::GetVectorAndAngle ( gp_Vec & theAxis,
double & theAngle ) const

Convert a quaternion to Axis+Angle representation, preserve the axis direction and angle from -PI to +PI.

◆ Invert()

constexpr void gp_Quaternion::Invert ( )
inlineconstexpr

Inverts quaternion (both rotation direction and norm)

◆ Inverted()

constexpr gp_Quaternion gp_Quaternion::Inverted ( ) const
inlineconstexpr

Return inversed quaternion q^-1.

◆ IsEqual()

bool gp_Quaternion::IsEqual ( const gp_Quaternion & theOther) const

Simple equal test without precision.

◆ Multiplied()

constexpr gp_Quaternion gp_Quaternion::Multiplied ( const gp_Quaternion & theOther) const
inlineconstexprnoexcept

Multiply function - work the same as Matrices multiplying.

qq' = (cross(v,v') + wv' + w'v, ww' - dot(v,v'))
STL input iterator that wraps an OCCT More()/Next() iterator.
Definition NCollection_ForwardRange.hxx:142

Result is rotation combination: q' than q (here q=this, q'=theQ). Notices that:

qq' != q'q;
qq^-1 = q;
GLdouble GLdouble GLdouble GLdouble q
Definition OpenGl_glext.h:353

◆ Multiply() [1/2]

void gp_Quaternion::Multiply ( const gp_Quaternion & theOther)
inline

Adds rotation by multiplication.

◆ Multiply() [2/2]

gp_Vec gp_Quaternion::Multiply ( const gp_Vec & theVec) const

Rotates vector by quaternion as rotation operator.

◆ Negated()

constexpr gp_Quaternion gp_Quaternion::Negated ( ) const
inlineconstexprnoexcept

Returns quaternion with all components negated. Note that this operation does not affect neither rotation operator defined by quaternion nor its norm.

◆ Norm()

double gp_Quaternion::Norm ( ) const
inline

Returns norm of quaternion.

◆ Normalize()

void gp_Quaternion::Normalize ( )

Scale quaternion that its norm goes to 1. The appearing of 0 magnitude or near is a error, so we can be sure that can divide by magnitude.

◆ Normalized()

gp_Quaternion gp_Quaternion::Normalized ( ) const
inline

Returns quaternion scaled so that its norm goes to 1.

◆ operator*() [1/3]

constexpr gp_Quaternion gp_Quaternion::operator* ( const double theScale) const
inlineconstexprnoexcept

◆ operator*() [2/3]

constexpr gp_Quaternion gp_Quaternion::operator* ( const gp_Quaternion & theOther) const
inlineconstexprnoexcept

◆ operator*() [3/3]

gp_Vec gp_Quaternion::operator* ( const gp_Vec & theVec) const
inline

◆ operator*=() [1/2]

void gp_Quaternion::operator*= ( const double theScale)
inline

◆ operator*=() [2/2]

void gp_Quaternion::operator*= ( const gp_Quaternion & theOther)
inline

◆ operator+()

constexpr gp_Quaternion gp_Quaternion::operator+ ( const gp_Quaternion & theOther) const
inlineconstexprnoexcept

◆ operator+=()

void gp_Quaternion::operator+= ( const gp_Quaternion & theOther)
inline

◆ operator-() [1/2]

constexpr gp_Quaternion gp_Quaternion::operator- ( ) const
inlineconstexprnoexcept

◆ operator-() [2/2]

constexpr gp_Quaternion gp_Quaternion::operator- ( const gp_Quaternion & theOther) const
inlineconstexprnoexcept

◆ operator-=()

void gp_Quaternion::operator-= ( const gp_Quaternion & theOther)
inline

◆ Reverse()

constexpr void gp_Quaternion::Reverse ( )
inlineconstexprnoexcept

Reverse direction of rotation (conjugate quaternion)

◆ Reversed()

constexpr gp_Quaternion gp_Quaternion::Reversed ( ) const
inlineconstexprnoexcept

Return rotation with reversed direction (conjugated quaternion)

◆ Scale()

constexpr void gp_Quaternion::Scale ( const double theScale)
inlineconstexprnoexcept

Scale all components by quaternion by theScale; note that rotation is not changed by this operation (except 0-scaling)

◆ Scaled()

constexpr gp_Quaternion gp_Quaternion::Scaled ( const double theScale) const
inlineconstexprnoexcept

Returns scaled quaternion.

◆ Set() [1/2]

constexpr void gp_Quaternion::Set ( const double theX,
const double theY,
const double theZ,
const double theW )
inlineconstexprnoexcept

◆ Set() [2/2]

constexpr void gp_Quaternion::Set ( const gp_Quaternion & theQuaternion)
inlineconstexprnoexcept

◆ SetEulerAngles()

void gp_Quaternion::SetEulerAngles ( const gp_EulerSequence theOrder,
const double theAlpha,
const double theBeta,
const double theGamma )

Create a unit quaternion representing rotation defined by generalized Euler angles.

◆ SetIdent()

constexpr void gp_Quaternion::SetIdent ( )
inlineconstexprnoexcept

Make identity quaternion (zero-rotation)

◆ SetMatrix()

void gp_Quaternion::SetMatrix ( const gp_Mat & theMat)

Create a unit quaternion by rotation matrix matrix must contain only rotation (not scale or shear)

For numerical stability we find first the greatest component of quaternion and than search others from this one

◆ SetRotation() [1/2]

void gp_Quaternion::SetRotation ( const gp_Vec & theVecFrom,
const gp_Vec & theVecTo )

Sets quaternion to shortest-arc rotation producing vector theVecTo from vector theVecFrom. If vectors theVecFrom and theVecTo are opposite then rotation axis is computed as theVecFrom ^ (1,0,0) or theVecFrom ^ (0,0,1).

◆ SetRotation() [2/2]

void gp_Quaternion::SetRotation ( const gp_Vec & theVecFrom,
const gp_Vec & theVecTo,
const gp_Vec & theHelpCrossVec )

Sets quaternion to shortest-arc rotation producing vector theVecTo from vector theVecFrom. If vectors theVecFrom and theVecTo are opposite then rotation axis is computed as theVecFrom ^ theHelpCrossVec.

◆ SetVectorAndAngle()

void gp_Quaternion::SetVectorAndAngle ( const gp_Vec & theAxis,
const double theAngle )

Create a unit quaternion from Axis+Angle representation.

◆ SquareNorm()

constexpr double gp_Quaternion::SquareNorm ( ) const
inlineconstexprnoexcept

Returns square norm of quaternion.

◆ StabilizeLength()

void gp_Quaternion::StabilizeLength ( )

Stabilize quaternion length within 1 - 1/4. This operation is a lot faster than normalization and preserve length goes to 0 or infinity.

◆ Subtract()

constexpr void gp_Quaternion::Subtract ( const gp_Quaternion & theOther)
inlineconstexprnoexcept

Subtracts components of other quaternion; result is "rotations mix".

◆ Subtracted()

constexpr gp_Quaternion gp_Quaternion::Subtracted ( const gp_Quaternion & theOther) const
inlineconstexprnoexcept

Makes difference of quaternion components; result is "rotations mix".

◆ W()

constexpr double gp_Quaternion::W ( ) const
inlineconstexprnoexcept

◆ X()

constexpr double gp_Quaternion::X ( ) const
inlineconstexprnoexcept

◆ Y()

constexpr double gp_Quaternion::Y ( ) const
inlineconstexprnoexcept

◆ Z()

constexpr double gp_Quaternion::Z ( ) const
inlineconstexprnoexcept

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