SOFA API  ca70b0f0
Open source framework for multi-physics simuation
sofa::type::Quat< Real > Class Template Reference

#include <Quat.h>

Inheritance diagram for sofa::type::Quat< Real >:

Static Public Attributes

static constexpr Size static_size = 4
 
static constexpr Size total_size = 4
 Compile-time constant specifying the number of scalars within this vector (equivalent to the size() method) More...
 
static constexpr Size spatial_dimensions = 3
 Compile-time constant specifying the number of dimensions of space (NOT equivalent to total_size for quaternions) More...
 

Public Member Functions

constexpr Quat ()
 
constexpr Quat (qNoInit)
 Fast constructor: no initialization. More...
 
 ~Quat ()=default
 
constexpr Quat (Real x, Real y, Real z, Real w)
 
template<class Real2 >
constexpr Quat (const Real2 q[])
 
template<class Real2 >
constexpr Quat (const Quat< Real2 > &q)
 
 Quat (const Vec3 &axis, Real angle)
 
 Quat (const Vec3 &vFrom, const Vec3 &vTo)
 
void set (Real x, Real y, Real z, Real w)
 
const Real * ptr () const
 Cast into a standard C array of elements. More...
 
Real * ptr ()
 Cast into a standard C array of elements. More...
 
bool isNormalized ()
 Returns true if norm of Quaternion is one, false otherwise. More...
 
void normalize ()
 Normalize a quaternion. More...
 
void clear ()
 
void fromFrame (const Vec3 &x, const Vec3 &y, const Vec3 &z)
 Convert the reference frame orientation into an orientation quaternion. More...
 
void fromMatrix (const Mat3x3 &m)
 Convert a rotation matrix into an orientation quaternion. More...
 
void toMatrix (Mat3x3 &m) const
 Convert the quaternion into an orientation matrix. More...
 
constexpr void toHomogeneousMatrix (Mat4x4 &m) const
 
constexpr auto rotate (const Vec3 &v) const -> Vec3
 Apply the rotation to a given vector. More...
 
constexpr auto inverseRotate (const Vec3 &v) const -> Vec3
 Apply the inverse rotation to a given vector. More...
 
auto operator+ (const Quat &q1) const -> Quat
 
constexpr auto operator* (const Quat &q1) const -> Quat
 
constexpr auto operator* (const Real &r) const -> Quat
 
auto operator/ (const Real &r) const -> Quat
 
void operator*= (const Real &r)
 
void operator/= (const Real &r)
 
constexpr auto quatVectMult (const Vec3 &vect) const -> Quat
 Given two Quats, multiply them together to get a third quaternion. More...
 
constexpr auto vectQuatMult (const Vec3 &vect) const -> Quat
 
constexpr Real & operator[] (Size index)
 
constexpr const Real & operator[] (Size index) const
 
auto inverse () const -> Quat
 
auto quatToRotationVector () const -> Vec3
 Given a quaternion, compute rotation vector (axis times angle) More...
 
auto toEulerVector () const -> Vec3
 
void slerp (const Quat &a, const Quat &b, Real t, bool allowFlip=true)
 Returns the slerp interpolation of Quaternions a and b, at time t. More...
 
constexpr void buildRotationMatrix (Real m[4][4]) const
 
constexpr void writeOpenGlMatrix (double *m) const
 
constexpr void writeOpenGlMatrix (float *m) const
 
auto axisToQuat (Vec3 a, Real phi) -> Quat
 Given an axis and angle, compute quaternion. More...
 
void quatToAxis (Vec3 &a, Real &phi) const
 Given a quaternion, compute an axis and angle. More...
 
void setFromUnitVectors (const Vec3 &vFrom, const Vec3 &vTo)
 Sets this quaternion to the rotation required to rotate direction vector vFrom to direction vector vTo. vFrom and vTo are assumed to be normalized. More...
 
auto slerp (const Quat &q1, Real t) const -> Quat
 
auto slerp2 (const Quat &q1, Real t) const -> Quat
 
void operator+= (const Quat &q2)
 
constexpr void operator*= (const Quat &q1)
 
bool operator== (const Quat &q) const
 
bool operator!= (const Quat &q) const
 

Static Public Member Functions

static Quat identity ()
 
static auto createQuaterFromFrame (const Vec3 &lox, const Vec3 &loy, const Vec3 &loz) -> Quat
 
static auto createFromRotationVector (const Vec3 &a) -> Quat
 Create using rotation vector (axis*angle) given in parent coordinates. More...
 
static auto createQuaterFromEuler (const Vec3 &v, EulerOrder order=EulerOrder::ZYX) -> Quat
 
static auto fromEuler (Real alpha, Real beta, Real gamma, EulerOrder order=EulerOrder::ZYX) -> Quat
 Create a quaternion from Euler angles. More...
 
static auto createFromRotationVector (Real a0, Real a1, Real a2) -> Quat
 Create using the entries of a rotation vector (axis*angle) given in parent coordinates. More...
 
static auto set (const Vec3 &a)
 Create using rotation vector (axis*angle) given in parent coordinates. More...
 
static auto set (Real a0, Real a1, Real a2)
 Create using using the entries of a rotation vector (axis*angle) given in parent coordinates. More...
 
static auto quatDiff (Quat a, const Quat &b) -> Quat
 Return the quaternion resulting of the movement between 2 quaternions. More...
 
static auto angularDisplacement (const Quat &a, const Quat &b) -> Vec3
 Return the eulerian vector resulting of the movement between 2 quaternions. More...
 
static Size size ()
 

Attribute details

◆ spatial_dimensions

template<class Real >
constexpr Size sofa::type::Quat< Real >::spatial_dimensions = 3
staticconstexpr

Compile-time constant specifying the number of dimensions of space (NOT equivalent to total_size for quaternions)

◆ static_size

template<class Real >
constexpr Size sofa::type::Quat< Real >::static_size = 4
staticconstexpr

◆ total_size

template<class Real >
constexpr Size sofa::type::Quat< Real >::total_size = 4
staticconstexpr

Compile-time constant specifying the number of scalars within this vector (equivalent to the size() method)

Constructor details

◆ Quat() [1/7]

template<class Real >
constexpr sofa::type::Quat< Real >::Quat ( )
inlineconstexpr

◆ Quat() [2/7]

template<class Real >
constexpr sofa::type::Quat< Real >::Quat ( qNoInit  )
inlineexplicitconstexpr

Fast constructor: no initialization.

◆ ~Quat()

template<class Real >
sofa::type::Quat< Real >::~Quat ( )
default

◆ Quat() [3/7]

template<class Real >
constexpr sofa::type::Quat< Real >::Quat ( Real  x,
Real  y,
Real  z,
Real  w 
)
inlineconstexpr

◆ Quat() [4/7]

template<class Real >
template<class Real2 >
constexpr sofa::type::Quat< Real >::Quat ( const Real2  q[])
inlineconstexpr

◆ Quat() [5/7]

template<class Real >
template<class Real2 >
constexpr sofa::type::Quat< Real >::Quat ( const Quat< Real2 > &  q)
inlineconstexpr

◆ Quat() [6/7]

template<class Real >
sofa::type::Quat< Real >::Quat ( const Vec3 axis,
Real  angle 
)

◆ Quat() [7/7]

template<class Real >
sofa::type::Quat< Real >::Quat ( const Vec3 vFrom,
const Vec3 vTo 
)

Sets this quaternion to the rotation required to rotate direction vector vFrom to direction vector vTo.
vFrom and vTo are assumed to be normalized.

Function details

◆ angularDisplacement()

template<class Real >
auto sofa::type::Quat< Real >::angularDisplacement ( const Quat< Real > &  a,
const Quat< Real > &  b 
) -> Vec3
static

Return the eulerian vector resulting of the movement between 2 quaternions.

◆ axisToQuat()

template<class Real >
auto sofa::type::Quat< Real >::axisToQuat ( Vec3  a,
Real  phi 
) -> Quat

Given an axis and angle, compute quaternion.

This function computes a quaternion based on an axis (defined by the given vector) and an angle about which to rotate. The angle is expressed in radians.

◆ buildRotationMatrix()

template<class Real >
constexpr void sofa::type::Quat< Real >::buildRotationMatrix ( Real  m[4][4]) const
inlineconstexpr

A useful function, builds a rotation matrix in Matrix based on given quaternion.

◆ clear()

template<class Real >
void sofa::type::Quat< Real >::clear ( )
inline

◆ createFromRotationVector() [1/2]

template<class Real >
auto sofa::type::Quat< Real >::createFromRotationVector ( const Vec3 a) -> Quat
static

Create using rotation vector (axis*angle) given in parent coordinates.

◆ createFromRotationVector() [2/2]

template<class Real >
auto sofa::type::Quat< Real >::createFromRotationVector ( Real  a0,
Real  a1,
Real  a2 
) -> Quat
static

Create using the entries of a rotation vector (axis*angle) given in parent coordinates.

◆ createQuaterFromEuler()

template<class Real >
auto sofa::type::Quat< Real >::createQuaterFromEuler ( const Vec3 v,
EulerOrder  order = EulerOrder::ZYX 
) -> Quat
static

◆ createQuaterFromFrame()

template<class Real >
auto sofa::type::Quat< Real >::createQuaterFromFrame ( const Vec3 lox,
const Vec3 loy,
const Vec3 loz 
) -> Quat
static

◆ fromEuler()

template<class Real >
auto sofa::type::Quat< Real >::fromEuler ( Real  alpha,
Real  beta,
Real  gamma,
EulerOrder  order = EulerOrder::ZYX 
) -> Quat
static

Create a quaternion from Euler angles.

◆ fromFrame()

template<class Real >
void sofa::type::Quat< Real >::fromFrame ( const Vec3 x,
const Vec3 y,
const Vec3 z 
)

Convert the reference frame orientation into an orientation quaternion.

◆ fromMatrix()

template<class Real >
void sofa::type::Quat< Real >::fromMatrix ( const Mat3x3 m)

Convert a rotation matrix into an orientation quaternion.

◆ identity()

template<class Real >
static Quat sofa::type::Quat< Real >::identity ( )
inlinestatic

◆ inverse()

template<class Real >
auto sofa::type::Quat< Real >::inverse

◆ inverseRotate()

template<class Real >
constexpr auto sofa::type::Quat< Real >::inverseRotate ( const Vec3 v) const -> Vec3
inlineconstexpr

Apply the inverse rotation to a given vector.

◆ isNormalized()

template<class Real >
bool sofa::type::Quat< Real >::isNormalized

Returns true if norm of Quaternion is one, false otherwise.

Returns true if norm of Quatnion is one, false otherwise.

◆ normalize()

template<class Real >
void sofa::type::Quat< Real >::normalize

Normalize a quaternion.

Quat<Real>s always obey: a^2 + b^2 + c^2 + d^2 = 1.0 If they don't add up to 1.0, dividing by their magnitude will renormalize them.

◆ operator!=()

template<class Real >
bool sofa::type::Quat< Real >::operator!= ( const Quat< Real > &  q) const

◆ operator*() [1/2]

template<class Real >
constexpr auto sofa::type::Quat< Real >::operator* ( const Quat< Real > &  q1) const -> Quat
inlineconstexpr

◆ operator*() [2/2]

template<class Real >
constexpr auto sofa::type::Quat< Real >::operator* ( const Real &  r) const -> Quat
inlineconstexpr

◆ operator*=() [1/2]

template<class Real >
constexpr void sofa::type::Quat< Real >::operator*= ( const Quat< Real > &  q1)
inlineconstexpr

◆ operator*=() [2/2]

template<class Real >
void sofa::type::Quat< Real >::operator*= ( const Real &  r)
inline

◆ operator+()

template<class Real >
auto sofa::type::Quat< Real >::operator+ ( const Quat< Real > &  q1) const -> Quat

Given two quaternions, add them together to get a third quaternion. Adding quaternions to get a compound rotation is analagous to adding translations to get a compound translation.

Given two rotations, e1 and e2, expressed as quaternion rotations, figure out the equivalent single rotation and stuff it into dest. NOTE: This routine is written so that q1 or q2 may be the same as dest (or each other).

◆ operator+=()

template<class Real >
void sofa::type::Quat< Real >::operator+= ( const Quat< Real > &  q2)

◆ operator/()

template<class Real >
auto sofa::type::Quat< Real >::operator/ ( const Real &  r) const -> Quat
inline

◆ operator/=()

template<class Real >
void sofa::type::Quat< Real >::operator/= ( const Real &  r)
inline

◆ operator==()

template<class Real >
bool sofa::type::Quat< Real >::operator== ( const Quat< Real > &  q) const

◆ operator[]() [1/2]

template<class Real >
constexpr Real& sofa::type::Quat< Real >::operator[] ( Size  index)
inlineconstexpr

◆ operator[]() [2/2]

template<class Real >
constexpr const Real& sofa::type::Quat< Real >::operator[] ( Size  index) const
inlineconstexpr

◆ ptr() [1/2]

template<class Real >
Real* sofa::type::Quat< Real >::ptr ( )
inline

Cast into a standard C array of elements.

◆ ptr() [2/2]

template<class Real >
const Real* sofa::type::Quat< Real >::ptr ( ) const
inline

Cast into a standard C array of elements.

◆ quatDiff()

template<class Real >
Quat< Real > sofa::type::Quat< Real >::quatDiff ( Quat< Real >  a,
const Quat< Real > &  b 
) -> Quat
static

Return the quaternion resulting of the movement between 2 quaternions.

◆ quatToAxis()

template<class Real >
void sofa::type::Quat< Real >::quatToAxis ( Vec3 a,
Real &  phi 
) const

Given a quaternion, compute an axis and angle.

◆ quatToRotationVector()

template<class Real >
auto sofa::type::Quat< Real >::quatToRotationVector

Given a quaternion, compute rotation vector (axis times angle)

◆ quatVectMult()

template<class Real >
constexpr auto sofa::type::Quat< Real >::quatVectMult ( const Vec3 vect) const -> Quat
inlineconstexpr

Given two Quats, multiply them together to get a third quaternion.

◆ rotate()

template<class Real >
constexpr auto sofa::type::Quat< Real >::rotate ( const Vec3 v) const -> Vec3
inlineconstexpr

Apply the rotation to a given vector.

◆ set() [1/3]

template<class Real >
static auto sofa::type::Quat< Real >::set ( const Vec3 a)
inlinestatic

Create using rotation vector (axis*angle) given in parent coordinates.

◆ set() [2/3]

template<class Real >
static auto sofa::type::Quat< Real >::set ( Real  a0,
Real  a1,
Real  a2 
)
inlinestatic

Create using using the entries of a rotation vector (axis*angle) given in parent coordinates.

◆ set() [3/3]

template<class Real >
void sofa::type::Quat< Real >::set ( Real  x,
Real  y,
Real  z,
Real  w 
)
inline

◆ setFromUnitVectors()

template<class Real >
void sofa::type::Quat< Real >::setFromUnitVectors ( const Vec3 vFrom,
const Vec3 vTo 
)

Sets this quaternion to the rotation required to rotate direction vector vFrom to direction vector vTo. vFrom and vTo are assumed to be normalized.

◆ size()

template<class Real >
static Size sofa::type::Quat< Real >::size ( void  )
inlinestatic

◆ slerp() [1/2]

template<class Real >
void sofa::type::Quat< Real >::slerp ( const Quat< Real > &  a,
const Quat< Real > &  b,
Real  t,
bool  allowFlip = true 
)

Returns the slerp interpolation of Quaternions a and b, at time t.

t should range in [0,1]. Result is a when t=0 and b when t=1. When allowFlip is true (default) the slerp interpolation will always use the "shortest path" between the Quaternions' orientations, by "flipping" the source Quaternion if needed (see negate()).

t should range in [0,1]. Result is a when t=0 and b when t=1.

When allowFlip is true (default) the slerp interpolation will always use the "shortest path" between the Quaternions' orientations, by "flipping" the source Quatnion if needed (see negate()).

◆ slerp() [2/2]

template<class Real >
auto sofa::type::Quat< Real >::slerp ( const Quat< Real > &  q1,
Real  t 
) const -> Quat

◆ slerp2()

template<class Real >
auto sofa::type::Quat< Real >::slerp2 ( const Quat< Real > &  q1,
Real  t 
) const -> Quat

◆ toEulerVector()

template<class Real >
auto sofa::type::Quat< Real >::toEulerVector

Compute the Euler angles: Roll: rotation about the X-axis Pitch: rotation about the Y-axis Yaw: rotation about the Z-axis

◆ toHomogeneousMatrix()

template<class Real >
constexpr void sofa::type::Quat< Real >::toHomogeneousMatrix ( Mat4x4 m) const
inlineconstexpr

Convert the quaternion into an orientation homogeneous matrix The homogeneous part is set to 0,0,0,1

◆ toMatrix()

template<class Real >
void sofa::type::Quat< Real >::toMatrix ( Mat3x3 m) const
inline

Convert the quaternion into an orientation matrix.

◆ vectQuatMult()

template<class Real >
constexpr auto sofa::type::Quat< Real >::vectQuatMult ( const Vec3 vect) const -> Quat
inlineconstexpr

◆ writeOpenGlMatrix() [1/2]

template<class Real >
constexpr void sofa::type::Quat< Real >::writeOpenGlMatrix ( double *  m) const
inlineconstexpr

◆ writeOpenGlMatrix() [2/2]

template<class Real >
constexpr void sofa::type::Quat< Real >::writeOpenGlMatrix ( float m) const
inlineconstexpr

Enum details

◆ EulerOrder

template<class Real >
enum sofa::type::Quat::EulerOrder
strong

Create a quaternion from Euler angles Thanks to https://github.com/mrdoob/three.js/blob/dev/src/math/Quaternion.js#L199

Enumerator
XYZ 
YXZ 
ZXY 
ZYX 
YZX 
XZY