Open CASCADE Technology  7.4.0
Public Member Functions

gp_Quaternion Class Reference

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

#include <gp_Quaternion.hxx>

Public Member Functions

 gp_Quaternion ()
 Creates an identity quaternion. More...
 
 gp_Quaternion (const Standard_Real x, const Standard_Real y, const Standard_Real z, const Standard_Real w)
 Creates quaternion directly from component values. More...
 
 gp_Quaternion (const gp_Quaternion &theToCopy)
 Creates copy of another quaternion. More...
 
 gp_Quaternion (const gp_Vec &theVecFrom, const gp_Vec &theVecTo)
 Creates quaternion representing shortest-arc rotation operator producing vector theVecTo from vector theVecFrom. More...
 
 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. More...
 
 gp_Quaternion (const gp_Vec &theAxis, const Standard_Real theAngle)
 Creates quaternion representing rotation on angle theAngle around vector theAxis. More...
 
 gp_Quaternion (const gp_Mat &theMat)
 Creates quaternion from rotation matrix 3*3 (which should be orthonormal skew-symmetric matrix) More...
 
Standard_Boolean IsEqual (const gp_Quaternion &theOther) const
 Simple equal test without precision. More...
 
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). More...
 
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. More...
 
void SetVectorAndAngle (const gp_Vec &theAxis, const Standard_Real theAngle)
 Create a unit quaternion from Axis+Angle representation. More...
 
void GetVectorAndAngle (gp_Vec &theAxis, Standard_Real &theAngle) const
 Convert a quaternion to Axis+Angle representation, preserve the axis direction and angle from -PI to +PI. More...
 
void SetMatrix (const gp_Mat &theMat)
 Create a unit quaternion by rotation matrix matrix must contain only rotation (not scale or shear) More...
 
gp_Mat GetMatrix () const
 Returns rotation operation as 3*3 matrix. More...
 
void SetEulerAngles (const gp_EulerSequence theOrder, const Standard_Real theAlpha, const Standard_Real theBeta, const Standard_Real theGamma)
 Create a unit quaternion representing rotation defined by generalized Euler angles. More...
 
void GetEulerAngles (const gp_EulerSequence theOrder, Standard_Real &theAlpha, Standard_Real &theBeta, Standard_Real &theGamma) const
 Returns Euler angles describing current rotation. More...
 
void Set (const Standard_Real x, const Standard_Real y, const Standard_Real z, const Standard_Real w)
 
void Set (const gp_Quaternion &theQuaternion)
 
Standard_Real X () const
 
Standard_Real Y () const
 
Standard_Real Z () const
 
Standard_Real W () const
 
void SetIdent ()
 Make identity quaternion (zero-rotation) More...
 
void Reverse ()
 Reverse direction of rotation (conjugate quaternion) More...
 
gp_Quaternion Reversed () const
 Return rotation with reversed direction (conjugated quaternion) More...
 
void Invert ()
 Inverts quaternion (both rotation direction and norm) More...
 
gp_Quaternion Inverted () const
 Return inversed quaternion q^-1. More...
 
Standard_Real SquareNorm () const
 Returns square norm of quaternion. More...
 
Standard_Real Norm () const
 Returns norm of quaternion. More...
 
void Scale (const Standard_Real theScale)
 Scale all components by quaternion by theScale; note that rotation is not changed by this operation (except 0-scaling) More...
 
void operator*= (const Standard_Real theScale)
 
gp_Quaternion Scaled (const Standard_Real theScale) const
 Returns scaled quaternion. More...
 
gp_Quaternion operator* (const Standard_Real theScale) const
 
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. More...
 
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. More...
 
gp_Quaternion Normalized () const
 Returns quaternion scaled so that its norm goes to 1. More...
 
gp_Quaternion Negated () const
 Returns quaternion with all components negated. Note that this operation does not affect neither rotation operator defined by quaternion nor its norm. More...
 
gp_Quaternion operator- () const
 
gp_Quaternion Added (const gp_Quaternion &theOther) const
 Makes sum of quaternion components; result is "rotations mix". More...
 
gp_Quaternion operator+ (const gp_Quaternion &theOther) const
 
gp_Quaternion Subtracted (const gp_Quaternion &theOther) const
 Makes difference of quaternion components; result is "rotations mix". More...
 
gp_Quaternion operator- (const gp_Quaternion &theOther) const
 
gp_Quaternion Multiplied (const gp_Quaternion &theOther) const
 Multiply function - work the same as Matrices multiplying. qq' = (cross(v,v') + wv' + w'v, ww' - dot(v,v')) Result is rotation combination: q' than q (here q=this, q'=theQ). Notices than: qq' != q'q; qq^-1 = q;. More...
 
gp_Quaternion operator* (const gp_Quaternion &theOther) const
 
void Add (const gp_Quaternion &theOther)
 Adds componnets of other quaternion; result is "rotations mix". More...
 
void operator+= (const gp_Quaternion &theOther)
 
void Subtract (const gp_Quaternion &theOther)
 Subtracts componnets of other quaternion; result is "rotations mix". More...
 
void operator-= (const gp_Quaternion &theOther)
 
void Multiply (const gp_Quaternion &theOther)
 Adds rotation by multiplication. More...
 
void operator*= (const gp_Quaternion &theOther)
 
Standard_Real Dot (const gp_Quaternion &theOther) const
 Computes inner product / scalar product / Dot. More...
 
Standard_Real GetRotationAngle () const
 Return rotation angle from -PI to PI. More...
 
gp_Vec Multiply (const gp_Vec &theVec) const
 Rotates vector by quaternion as rotation operator. More...
 
gp_Vec operator* (const gp_Vec &theVec) const
 

Detailed Description

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

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

Constructor & Destructor Documentation

◆ gp_Quaternion() [1/7]

gp_Quaternion::gp_Quaternion ( )

Creates an identity quaternion.

◆ gp_Quaternion() [2/7]

gp_Quaternion::gp_Quaternion ( const Standard_Real  x,
const Standard_Real  y,
const Standard_Real  z,
const Standard_Real  w 
)

Creates quaternion directly from component values.

◆ gp_Quaternion() [3/7]

gp_Quaternion::gp_Quaternion ( const gp_Quaternion theToCopy)

Creates copy of another quaternion.

◆ gp_Quaternion() [4/7]

gp_Quaternion::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() [5/7]

gp_Quaternion::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() [6/7]

gp_Quaternion::gp_Quaternion ( const gp_Vec theAxis,
const Standard_Real  theAngle 
)

Creates quaternion representing rotation on angle theAngle around vector theAxis.

◆ gp_Quaternion() [7/7]

gp_Quaternion::gp_Quaternion ( const gp_Mat theMat)

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

Member Function Documentation

◆ Add()

void gp_Quaternion::Add ( const gp_Quaternion theOther)

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

◆ Added()

gp_Quaternion gp_Quaternion::Added ( const gp_Quaternion theOther) const

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

◆ Dot()

Standard_Real gp_Quaternion::Dot ( const gp_Quaternion theOther) const

Computes inner product / scalar product / Dot.

◆ GetEulerAngles()

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

Returns Euler angles describing current rotation.

◆ GetMatrix()

gp_Mat gp_Quaternion::GetMatrix ( ) const

Returns rotation operation as 3*3 matrix.

◆ GetRotationAngle()

Standard_Real gp_Quaternion::GetRotationAngle ( ) const

Return rotation angle from -PI to PI.

◆ GetVectorAndAngle()

void gp_Quaternion::GetVectorAndAngle ( gp_Vec theAxis,
Standard_Real theAngle 
) const

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

◆ Invert()

void gp_Quaternion::Invert ( )

Inverts quaternion (both rotation direction and norm)

◆ Inverted()

gp_Quaternion gp_Quaternion::Inverted ( ) const

Return inversed quaternion q^-1.

◆ IsEqual()

Standard_Boolean gp_Quaternion::IsEqual ( const gp_Quaternion theOther) const

Simple equal test without precision.

◆ Multiplied()

gp_Quaternion gp_Quaternion::Multiplied ( const gp_Quaternion theOther) const

Multiply function - work the same as Matrices multiplying. qq' = (cross(v,v') + wv' + w'v, ww' - dot(v,v')) Result is rotation combination: q' than q (here q=this, q'=theQ). Notices than: qq' != q'q; qq^-1 = q;.

◆ Multiply() [1/2]

void gp_Quaternion::Multiply ( const gp_Quaternion theOther)

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()

gp_Quaternion gp_Quaternion::Negated ( ) const

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

◆ Norm()

Standard_Real gp_Quaternion::Norm ( ) const

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

Returns quaternion scaled so that its norm goes to 1.

◆ operator*() [1/3]

gp_Quaternion gp_Quaternion::operator* ( const Standard_Real  theScale) const
inline

◆ operator*() [2/3]

gp_Quaternion gp_Quaternion::operator* ( const gp_Quaternion theOther) const
inline

◆ operator*() [3/3]

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

◆ operator*=() [1/2]

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

◆ operator*=() [2/2]

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

◆ operator+()

gp_Quaternion gp_Quaternion::operator+ ( const gp_Quaternion theOther) const
inline

◆ operator+=()

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

◆ operator-() [1/2]

gp_Quaternion gp_Quaternion::operator- ( ) const
inline

◆ operator-() [2/2]

gp_Quaternion gp_Quaternion::operator- ( const gp_Quaternion theOther) const
inline

◆ operator-=()

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

◆ Reverse()

void gp_Quaternion::Reverse ( )

Reverse direction of rotation (conjugate quaternion)

◆ Reversed()

gp_Quaternion gp_Quaternion::Reversed ( ) const

Return rotation with reversed direction (conjugated quaternion)

◆ Scale()

void gp_Quaternion::Scale ( const Standard_Real  theScale)

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

◆ Scaled()

gp_Quaternion gp_Quaternion::Scaled ( const Standard_Real  theScale) const

Returns scaled quaternion.

◆ Set() [1/2]

void gp_Quaternion::Set ( const Standard_Real  x,
const Standard_Real  y,
const Standard_Real  z,
const Standard_Real  w 
)

◆ Set() [2/2]

void gp_Quaternion::Set ( const gp_Quaternion theQuaternion)

◆ SetEulerAngles()

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

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

◆ SetIdent()

void gp_Quaternion::SetIdent ( )

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 Standard_Real  theAngle 
)

Create a unit quaternion from Axis+Angle representation.

◆ SquareNorm()

Standard_Real gp_Quaternion::SquareNorm ( ) const

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()

void gp_Quaternion::Subtract ( const gp_Quaternion theOther)

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

◆ Subtracted()

gp_Quaternion gp_Quaternion::Subtracted ( const gp_Quaternion theOther) const

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

◆ W()

Standard_Real gp_Quaternion::W ( ) const

◆ X()

Standard_Real gp_Quaternion::X ( ) const

◆ Y()

Standard_Real gp_Quaternion::Y ( ) const

◆ Z()

Standard_Real gp_Quaternion::Z ( ) const

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