Quaternion< ValueType > Class Template Reference Math Library

#include <quaternion.h>

详细描述

template<typename ValueType>
class maxon::Quaternion< ValueType >

Quaternions extend the concept of rotation in three dimensions to rotation in four dimensions. This avoids the problem of "gimbal-lock" and allows for the implementation of smooth and continuous rotation. In effect, they may be considered to add an additional rotation angle to spherical coordinates ie. Longitude, Latitude and Rotation angles. A Quaternion is defined using four floating point values |v.x v.y v.z w|. These are calculated from the combination of the three coordinates of the rotation axis and the rotation angle. Because the rotation axis is specified as a unit direction vector, it may be calculated through vector mathematics or from spherical coordinates ie. (longitude/latitude). Quaternions offer another advantage in that they be interpolated - this allows for smooth and predictable rotation effects.

公共成员函数

  Quaternion ()
MAXON_IMPLICIT   Quaternion (const VectorType & v , const ValueType w )
MAXON_IMPLICIT   Quaternion (const ValueType x, const ValueType y, const ValueType z, const ValueType w )
const QuaternionType operator+= (const QuaternionType & v )
const QuaternionType operator-= (const QuaternionType & v )
const QuaternionType operator*= (const QuaternionType & v )
QuaternionType   operator+ (const QuaternionType & v ) const
QuaternionType   operator- (const QuaternionType & v ) const
QuaternionType   operator* (const QuaternionType & v ) const
QuaternionType   operator* (const ValueType s) const
void  SetMatrix (const MatrixType &m)
void  SetRotation (const VectorType &rotation)
void  SetAxisRotation (const VectorType &axis, const ValueType rotation)
MatrixType   GetMatrix () const
Result < void >  GetAxisRotation ( VectorType &axis, ValueType &angle) const
ValueType  GetSquaredLength () const
ValueType  GetLength () const
Result < QuaternionType GetNormalized () const
Result < QuaternionType GetInverse () const
QuaternionType   GetConjugate () const
Result < QuaternionType GetLog () const
Result < QuaternionType GetExp () const
Result < QuaternionType GetPow (const ValueType &t) const
String   ToString (const FormatStatement *formatStatement=nullptr) const
  MAXON_OPERATOR_EQUALITY_HASHCODE ( Quaternion , v , w )

静态公共成员函数

static ValueType  GetDot (const QuaternionType &q1, const QuaternionType &q2)
static Result < QuaternionType GetLerp (const QuaternionType &q1, const QuaternionType &q2, const ValueType t)
static Result < QuaternionType GetSlerp (const QuaternionType &q1, const QuaternionType &q2, const ValueType t)
static Result < QuaternionType GetSquad (const QuaternionType &qi, const QuaternionType &qi_p1, const QuaternionType &si, const QuaternionType &si_p1, const ValueType t)
static Result < QuaternionType GetInnerQuaternion (const QuaternionType &qi_m1, const QuaternionType &qi, const QuaternionType &qi_p1)
static Result < QuaternionType GetSpline (const QuaternionType &qi_m1, const QuaternionType &qi, const QuaternionType &qi_p1, const QuaternionType &qi_p2, const ValueType t)
static Result < void >  DescribeIO (const DataSerializeInterface &stream)

Public Attributes

VectorType   v
ValueType  w

Private Types

using  VectorType = Vec3 < ValueType >
using  MatrixType = SqrMat3 < Vec3 < ValueType > >
using  QuaternionType = Quaternion < ValueType >

私有成员函数

ValueType  MyCopysign (const ValueType &x, const ValueType &y) const

Friends

QuaternionType   operator* (const ValueType s, const QuaternionType &q)

Member Typedef Documentation

◆  VectorType

using VectorType = Vec3 <ValueType>
private

◆  MatrixType

using MatrixType = SqrMat3 < Vec3 <ValueType> >
private

◆  QuaternionType

using QuaternionType = Quaternion <ValueType>
private

构造函数 & 析构函数文档编制

◆  Quaternion() [1/3]

Quaternion

Creates a quaternion initialized with default values (all components 0.0).

◆  Quaternion() [2/3]

Quaternion ( const VectorType v ,
const ValueType  w  
)

Creates a quaternion and initialize it with given quaternion values.

◆  Quaternion() [3/3]

Quaternion ( const ValueType  x ,
const ValueType  y ,
const ValueType  z ,
const ValueType  w  
)

Creates a quaternion and initialize it with given quaternion values.

成员函数文档编制

◆  MyCopysign()

ValueType MyCopysign ( const ValueType &  x ,
const ValueType &  y  
) const
private

◆  operator+=()

const Quaternion < ValueType > & operator+= ( const QuaternionType v )

Adds the components of two quaternions.

◆  operator-=()

const Quaternion < ValueType > & operator-= ( const QuaternionType v )

Subtract the components of two quaternions.

◆  operator*=()

const Quaternion < ValueType > & operator*= ( const QuaternionType v )

Concatenate two quaternion operations.

◆  operator+()

Quaternion < ValueType > operator+ ( const QuaternionType v ) const

Adds the components of two quaternions.

◆  operator-()

Quaternion < ValueType > operator- ( const QuaternionType v ) const

Subtracts the components of two quaternions.

◆  operator*() [1/2]

Quaternion < ValueType > operator* ( const QuaternionType v ) const

Concatenates two quaternion operations.

◆  operator*() [2/2]

Quaternion < ValueType > operator* ( const ValueType  s ) const

Scales the components of a quaternion.

◆  SetMatrix()

void SetMatrix ( const MatrixType m )

Converts a rotation matrix into a quaternion.

参数
[in] m Rotation matrix (does not need to be normalized).

◆  SetRotation()

void SetRotation ( const VectorType rotation )

Converts a rotation of order X -> Y -> Z into a quaternion.

参数
[in] rotation Rotation angle vector in radians.

◆  SetAxisRotation()

void SetAxisRotation ( const VectorType axis ,
const ValueType  rotation  
)

Converts an axis and angle to a quaternion.

参数
[in] axis Axis (does not need to be normalized).
[in] rotation Rotation angle in radians.

◆  GetMatrix()

auto GetMatrix

Derives a rotation matrix from the quaternion.

◆  GetAxisRotation()

Result < void > GetAxisRotation ( VectorType axis ,
ValueType &  angle  
) const

Calculate axis and rotation angle from quaternion

参数
[out] axis axis vector
[out] angle angle value in radians
返回
OK on success. Returns an error if quaternion is not normalized or the direction of the axis is undefined (singularity at 0 / 180 degree)

◆  GetSquaredLength()

ValueType GetSquaredLength

Calculates the squared magntitude/length/norm of a quaternion.

◆  GetLength()

ValueType GetLength

Calculates the magntitude/length/norm of a quaternion.

◆  GetNormalized()

Result < Quaternion < ValueType > > GetNormalized

Calculates the normalized quaternion.

返回
OK on sucess. Returns an error if the length of the quaternion is zero

◆  GetInverse()

Result < Quaternion < ValueType > > GetInverse

Calculates the inverse of a quaternion.

返回
OK on sucess. Returns an error if the length of the quaternion is zero

◆  GetConjugate()

Quaternion < ValueType > GetConjugate

Calculates the conjugate of a quaternion.

返回
conjugated quaternion

◆  GetLog()

Result < Quaternion < ValueType > > GetLog

Calculates the logarithm of a quaternion.

返回
OK on sucess. Returns an error if the length of the quaternion axis is zero

◆  GetExp()

Result < Quaternion < ValueType > > GetExp

Calculates the exponential of a quaternion.

返回
OK on sucess. Returns an error if the length of the quaternion is zero

◆  GetPow()

Result < Quaternion < ValueType > > GetPow ( const ValueType &  t ) const

Calculates the quaternion power q^t.

参数
[in] t exponent
返回
OK on sucess. Returns an error if the length of the quaternion is zero

◆  GetDot()

ValueType GetDot ( const QuaternionType q1 ,
const QuaternionType q2  
)
static

Calculates the dot product of two quaternions.

◆  GetLerp()

Result < Quaternion < ValueType > > GetLerp ( const QuaternionType q1 ,
const QuaternionType q2 ,
const ValueType  t  
)
static

Interpolates two quaternions linearly with blend parameter t.

参数
[in] q1 first quaternion
[in] q2 second quaternion
[in] t blend parameter [0.0, 1.0.]
返回
The interpolated quaternion.

◆  GetSlerp()

Result < Quaternion < ValueType > > GetSlerp ( const QuaternionType q1 ,
const QuaternionType q2 ,
const ValueType  t  
)
static

Interpolates two quaternions spherical linearly with blend parameter t.

参数
[in] q1 first quaternion
[in] q2 second quaternion
[in] t blend parameter [0.0, 1.0.]
返回
The interpolated quaternion.

◆  GetSquad()

Result < Quaternion < ValueType > > GetSquad ( const QuaternionType qi ,
const QuaternionType qi_p1 ,
const QuaternionType si ,
const QuaternionType si_p1 ,
const ValueType  t  
)
static

Spherical quadrangle interpolation of a sequence of quaternions qi and qi+1 with blend parameter t Additionally you have to specify the innner quaternions si and si+1.

参数
[in] qi main quaternion at index i
[in] qi_p1 main quaternion at index i+1
[in] si inner quaterniona at index i
[in] si_p1 inner quaternion at index i+1
[in] t blend parameter [0.0, 1.0.]
返回
The interpolated quaternion.

◆  GetInnerQuaternion()

Result < Quaternion < ValueType > > GetInnerQuaternion ( const QuaternionType qi_m1 ,
const QuaternionType qi ,
const QuaternionType qi_p1  
)
static

Computer the inner quaternion from the series of quaternions qi-1, qi and qi+1

参数
[in] qi_m1 quaternion at index i-1
[in] qi quaternion at index i
[in] qi_p1 quaternion at index i+1
返回
The interpolated quaternion.

◆  GetSpline()

Result < Quaternion < ValueType > > GetSpline ( const QuaternionType qi_m1 ,
const QuaternionType qi ,
const QuaternionType qi_p1 ,
const QuaternionType qi_p2 ,
const ValueType  t  
)
static

Interpolates two quaternions qi and qi+1 smoothly using spherical spline interpolation with parameter t. qi-1 and qi+2 are used to provide C1 continuity at the borders.

参数
[in] qi_m1 quaternion at index i-1
[in] qi quaternion at index i
[in] qi_p1 quaternion at index i+1
[in] qi_p2 quaternion at index i+2
[in] t blend parameter [0.0, 1.0.]
返回
The interpolated quaternion.

◆  ToString()

String ToString ( const FormatStatement formatStatement = nullptr ) const

Returns a readable string of the content.

参数
[in] formatStatement Nullptr or additional formatting instruction. See also Formatting Floating point values .
返回
The converted result.

◆  DescribeIO()

Result < void > DescribeIO ( const DataSerializeInterface stream )
static

Describe all elements of this class for I/O operations.

参数
[in] stream The stream that is used to register the class members.
返回
OK on success.

◆  MAXON_OPERATOR_EQUALITY_HASHCODE()

MAXON_OPERATOR_EQUALITY_HASHCODE ( Quaternion < ValueType >  ,
v   ,
w    
)

Friends And Related Function Documentation

◆  operator*

QuaternionType operator* ( const ValueType  s ,
const QuaternionType q  
)
friend

Scales the components of a quaternion with a scalar.

Member Data Documentation

◆  v

VectorType v

direction vector component

◆  w

ValueType w

angle component