Biorbd
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
biorbd::utils::Quaternion Class Reference

#include <Quaternion.h>

Inheritance diagram for biorbd::utils::Quaternion:

Public Member Functions

 Quaternion (double kStabilizer=1)
 Construct Quaternion. More...
 
 Quaternion (const biorbd::utils::Quaternion &other)
 Construct Quaternion from another quaternion. More...
 
 Quaternion (const RigidBodyDynamics::Math::Vector4d &vec4, double kStabilizer=1)
 Construct Quaternion. More...
 
 Quaternion (const biorbd::utils::Scalar &w, const biorbd::utils::Scalar &x, const biorbd::utils::Scalar &y, const biorbd::utils::Scalar &z, double kStabilizer=1)
 Construct Quaternion. More...
 
 Quaternion (const biorbd::utils::Scalar &w, const biorbd::utils::Vector3d &vec3, double kStabilizer=1)
 Construct Quaternion. More...
 
biorbd::utils::Scalar w () const
 Return the real part (w) the Quaternion. More...
 
biorbd::utils::Scalar x () const
 Return the X-Component of the imaginary part of the Quaternion. More...
 
biorbd::utils::Scalar y () const
 Return the Y-Component of the imaginary part of the Quaternion. More...
 
biorbd::utils::Scalar z () const
 Return the Z-Component of the imaginary part of the Quaternion. More...
 
void setKStab (double newKStab)
 Set the k stabilizer. More...
 
double kStab () const
 Return the k stabilizer. More...
 
biorbd::utils::Quaternion operator* (const biorbd::utils::Quaternion &other) const
 Quaternion multiplication. More...
 
biorbd::utils::Quaternion operator* (const biorbd::utils::Scalar &scalar) const
 Multiply the quaternion with a scalar. More...
 
biorbd::utils::Quaternion operator* (float scalar) const
 Multiply the quaternion with a scalar. More...
 
biorbd::utils::Quaternion operator+ (const biorbd::utils::Quaternion &other) const
 Add the quaternion to another. More...
 
biorbd::utils::Quaternion operator- (const biorbd::utils::Quaternion &other) const
 Subtract the quaternion to another. More...
 
biorbd::utils::Rotation toMatrix (bool skipAsserts=false) const
 Convert the quaternion to a RotoTrans. More...
 
biorbd::utils::Quaternion slerp (double alpha, const Quaternion &quat) const
 Interpolation of the quaternion between to position. More...
 
biorbd::utils::Quaternion conjugate () const
 Return the conjugate of the quaternion. More...
 
biorbd::utils::Quaternion timeStep (const biorbd::utils::Vector3d &omega, double dt)
 Integrate the quaternion from its velocity. More...
 
biorbd::utils::Vector3d rotate (const biorbd::utils::Vector3d &vec) const
 Return a rotated vector from the quaternion. More...
 
biorbd::utils::Quaternion omegaToQDot (const biorbd::utils::Vector3d &omega) const
 Converts a 3d angular velocity vector. More...
 
biorbd::utils::Vector3d eulerDotToOmega (const biorbd::utils::Vector3d &eulerDot, const biorbd::utils::Vector3d &euler, const biorbd::utils::String &seq)
 Converts a 3d angular velocity vector. More...
 
void derivate (const biorbd::utils::Vector &w)
 Return the time derivative of the quaterion. More...
 
void normalize ()
 Force the normalization of the quaternion. More...
 

Static Public Member Functions

static biorbd::utils::Quaternion fromGLRotate (const biorbd::utils::Scalar &angle, const biorbd::utils::Scalar &x, const biorbd::utils::Scalar &y, const biorbd::utils::Scalar &z, double kStab=1)
 Construct Quaternion from a GL. More...
 
static biorbd::utils::Quaternion fromAxisAngle (const biorbd::utils::Scalar &angle, const biorbd::utils::Vector3d &axis, double kStab=1)
 Construct Quaternion from an axis angle. More...
 
static biorbd::utils::Quaternion fromMatrix (const biorbd::utils::RotoTrans &rt, double kStab=1)
 Construct Quaternion from a RotoTrans matrix. More...
 
static biorbd::utils::Quaternion fromMatrix (const biorbd::utils::Rotation &mat, double kStab=1)
 Construct Quaternion from a Rotation matrix. More...
 
static biorbd::utils::Quaternion fromZYXAngles (const biorbd::utils::Vector3d &zyx_angles, double kStab=1)
 Construct Quaternion from Euler angles (sequece ZYX) More...
 
static biorbd::utils::Quaternion fromYXZAngles (const biorbd::utils::Vector3d &yxz_angles, double kStab=1)
 Construct Quaternion from Euler angles (sequece YXZ) More...
 
static biorbd::utils::Quaternion fromXYZAngles (const biorbd::utils::Vector3d &xyz_angles, double kStab=1)
 Construct Quaternion from Euler angles (sequece XYZ) More...
 

Protected Attributes

double m_Kstab
 Stabilization factor for the derivation.
 

Detailed Description

Description of a quaternion in the format (w, x, y, z)

The definition for conversions are taken from https://www.euclideanspace.com/maths/geometry/rotations/conversions/index.htm

Definition at line 26 of file Quaternion.h.

Constructor & Destructor Documentation

◆ Quaternion() [1/5]

biorbd::utils::Quaternion::Quaternion ( double  kStabilizer = 1)

Construct Quaternion.

Parameters
kStabilizerThe value of the kstabilizer

Definition at line 10 of file Quaternion.cpp.

◆ Quaternion() [2/5]

biorbd::utils::Quaternion::Quaternion ( const biorbd::utils::Quaternion other)

Construct Quaternion from another quaternion.

Parameters
otherOther quaternion

Definition at line 17 of file Quaternion.cpp.

◆ Quaternion() [3/5]

biorbd::utils::Quaternion::Quaternion ( const RigidBodyDynamics::Math::Vector4d &  vec4,
double  kStabilizer = 1 
)

Construct Quaternion.

Parameters
vec4The vector describing the quaternion
kStabilizerThe value of the kstabilizer

Definition at line 24 of file Quaternion.cpp.

◆ Quaternion() [4/5]

biorbd::utils::Quaternion::Quaternion ( const biorbd::utils::Scalar &  w,
const biorbd::utils::Scalar &  x,
const biorbd::utils::Scalar &  y,
const biorbd::utils::Scalar &  z,
double  kStabilizer = 1 
)

Construct Quaternion.

Parameters
wThe W-Component of quaternion
xThe X-Component of quaternion
yThe Y-Component of quaternion
zThe Z-Component of quaternion
kStabilizerThe value of the kstabilizer

Definition at line 33 of file Quaternion.cpp.

◆ Quaternion() [5/5]

biorbd::utils::Quaternion::Quaternion ( const biorbd::utils::Scalar &  w,
const biorbd::utils::Vector3d vec3,
double  kStabilizer = 1 
)

Construct Quaternion.

Parameters
wThe W-Component of quaternion
vec3The vector describing the imaginary part
kStabilizerThe value of the kstabilizer

Definition at line 44 of file Quaternion.cpp.

Member Function Documentation

◆ conjugate()

biorbd::utils::Quaternion biorbd::utils::Quaternion::conjugate ( ) const

Return the conjugate of the quaternion.

Returns
The conjugate of the quaternion

Definition at line 260 of file Quaternion.cpp.

◆ derivate()

void biorbd::utils::Quaternion::derivate ( const biorbd::utils::Vector w)

Return the time derivative of the quaterion.

Parameters
wThe vector of time derivative (output)

Definition at line 317 of file Quaternion.cpp.

◆ eulerDotToOmega()

biorbd::utils::Vector3d biorbd::utils::Quaternion::eulerDotToOmega ( const biorbd::utils::Vector3d eulerDot,
const biorbd::utils::Vector3d euler,
const biorbd::utils::String seq 
)

Converts a 3d angular velocity vector.

Parameters
eulerDotthe Euler angle rates
eulerthe Euler angles
seqthe Euler angles sequence

Converts a 3d angular velocity vector expressed in terms of euler angles rate into the 3d angular velocity vector expressed in the fixed parent frame. See https://davidbrown3.github.io/2017-07-25/EulerAngles/ for correct equations.

Definition at line 298 of file Quaternion.cpp.

◆ fromAxisAngle()

biorbd::utils::Quaternion biorbd::utils::Quaternion::fromAxisAngle ( const biorbd::utils::Scalar &  angle,
const biorbd::utils::Vector3d axis,
double  kStab = 1 
)
static

Construct Quaternion from an axis angle.

Parameters
angleThe angle in radians
axisThe 3d vector of the axis
kStabThe value of the kstabilizer

Definition at line 142 of file Quaternion.cpp.

◆ fromGLRotate()

biorbd::utils::Quaternion biorbd::utils::Quaternion::fromGLRotate ( const biorbd::utils::Scalar &  angle,
const biorbd::utils::Scalar &  x,
const biorbd::utils::Scalar &  y,
const biorbd::utils::Scalar &  z,
double  kStab = 1 
)
static

Construct Quaternion from a GL.

Parameters
angleThe angle in radians
xThe X-Component of quaternion
yThe Y-Component of quaternion
zThe Z-Component of quaternion
kStabThe value of the kstabilizer

Definition at line 130 of file Quaternion.cpp.

◆ fromMatrix() [1/2]

biorbd::utils::Quaternion biorbd::utils::Quaternion::fromMatrix ( const biorbd::utils::Rotation mat,
double  kStab = 1 
)
static

Construct Quaternion from a Rotation matrix.

Parameters
matThe rotation matrix
kStabThe value of the kstabilizer

Definition at line 161 of file Quaternion.cpp.

◆ fromMatrix() [2/2]

biorbd::utils::Quaternion biorbd::utils::Quaternion::fromMatrix ( const biorbd::utils::RotoTrans rt,
double  kStab = 1 
)
static

Construct Quaternion from a RotoTrans matrix.

Parameters
rtRotoTrans matrix
kStabThe value of the kstabilizer

Definition at line 155 of file Quaternion.cpp.

◆ fromXYZAngles()

biorbd::utils::Quaternion biorbd::utils::Quaternion::fromXYZAngles ( const biorbd::utils::Vector3d xyz_angles,
double  kStab = 1 
)
static

Construct Quaternion from Euler angles (sequece XYZ)

Parameters
xyz_anglesThe Euler angles in a sequence where the first element is the X-component
kStabThe value of the kstabilizer

Definition at line 189 of file Quaternion.cpp.

◆ fromYXZAngles()

biorbd::utils::Quaternion biorbd::utils::Quaternion::fromYXZAngles ( const biorbd::utils::Vector3d yxz_angles,
double  kStab = 1 
)
static

Construct Quaternion from Euler angles (sequece YXZ)

Parameters
yxz_anglesThe Euler angles in a sequence where the first element is the Y-component
kStabThe value of the kstabilizer

Definition at line 181 of file Quaternion.cpp.

◆ fromZYXAngles()

biorbd::utils::Quaternion biorbd::utils::Quaternion::fromZYXAngles ( const biorbd::utils::Vector3d zyx_angles,
double  kStab = 1 
)
static

Construct Quaternion from Euler angles (sequece ZYX)

Parameters
zyx_anglesThe Euler angles in a sequence where the first element is the Z-component
kStabThe value of the kstabilizer

Definition at line 173 of file Quaternion.cpp.

◆ kStab()

double biorbd::utils::Quaternion::kStab ( ) const

Return the k stabilizer.

Returns
The k stabilizer

The k statilizer value is used during several operation to make the quaternion tending toward a norm of $1$

Definition at line 75 of file Quaternion.cpp.

◆ normalize()

void biorbd::utils::Quaternion::normalize ( )

Force the normalization of the quaternion.

Definition at line 353 of file Quaternion.cpp.

◆ omegaToQDot()

biorbd::utils::Quaternion biorbd::utils::Quaternion::omegaToQDot ( const biorbd::utils::Vector3d omega) const

Converts a 3d angular velocity vector.

Parameters
omegathe angular velocity
Returns
a 4d vector containing the derivatives of the 4 components of the quaternion corresponding to omega

Converts a 3d angular velocity vector into a 4d derivative of the components of the quaternion

Definition at line 287 of file Quaternion.cpp.

◆ operator*() [1/3]

biorbd::utils::Quaternion biorbd::utils::Quaternion::operator* ( const biorbd::utils::Quaternion other) const

Quaternion multiplication.

Parameters
otherThe other quaternion

Definition at line 80 of file Quaternion.cpp.

◆ operator*() [2/3]

biorbd::utils::Quaternion biorbd::utils::Quaternion::operator* ( const biorbd::utils::Scalar &  scalar) const

Multiply the quaternion with a scalar.

Parameters
scalarThe scalar to multiply with

Definition at line 91 of file Quaternion.cpp.

◆ operator*() [3/3]

biorbd::utils::Quaternion biorbd::utils::Quaternion::operator* ( float  scalar) const

Multiply the quaternion with a scalar.

Parameters
scalarThe scalar to multiply with

Definition at line 98 of file Quaternion.cpp.

◆ operator+()

biorbd::utils::Quaternion biorbd::utils::Quaternion::operator+ ( const biorbd::utils::Quaternion other) const

Add the quaternion to another.

Parameters
otherThe other quaternion to add

Definition at line 116 of file Quaternion.cpp.

◆ operator-()

biorbd::utils::Quaternion biorbd::utils::Quaternion::operator- ( const biorbd::utils::Quaternion other) const

Subtract the quaternion to another.

Parameters
otherOther quaternion to substract

Definition at line 123 of file Quaternion.cpp.

◆ rotate()

biorbd::utils::Vector3d biorbd::utils::Quaternion::rotate ( const biorbd::utils::Vector3d vec) const

Return a rotated vector from the quaternion.

Parameters
vecThe vector to rotate
Returns
The rotated vector

Definition at line 276 of file Quaternion.cpp.

◆ setKStab()

void biorbd::utils::Quaternion::setKStab ( double  newKStab)

Set the k stabilizer.

Parameters
newKStabThe new value

Definition at line 70 of file Quaternion.cpp.

◆ slerp()

biorbd::utils::Quaternion biorbd::utils::Quaternion::slerp ( double  alpha,
const Quaternion quat 
) const

Interpolation of the quaternion between to position.

Parameters
alphaThe proportion of the rotation
quatThe quaternion to targe

Definition at line 219 of file Quaternion.cpp.

◆ timeStep()

biorbd::utils::Quaternion biorbd::utils::Quaternion::timeStep ( const biorbd::utils::Vector3d omega,
double  dt 
)

Integrate the quaternion from its velocity.

Parameters
omega3D vector of the angular velocity
dtThe time step to intergrate on
Returns
The rotated quaternion

Definition at line 268 of file Quaternion.cpp.

◆ toMatrix()

biorbd::utils::Rotation biorbd::utils::Quaternion::toMatrix ( bool  skipAsserts = false) const

Convert the quaternion to a RotoTrans.

Parameters
skipAssertsCheck if the norm of the quaternion is approximately 1
Returns
The rotation matrix

The function throws a runtime_error if the skipAsserts is false and the norm of the quaternion is not almost one. In order to accelerate the computation of the norm, the norm-squared is evaluated. The threshold is 1e-10 for the norm-squared

Definition at line 197 of file Quaternion.cpp.

◆ w()

biorbd::utils::Scalar biorbd::utils::Quaternion::w ( ) const

Return the real part (w) the Quaternion.

Returns
The real part of the Quaternion

Definition at line 53 of file Quaternion.cpp.

◆ x()

biorbd::utils::Scalar biorbd::utils::Quaternion::x ( ) const

Return the X-Component of the imaginary part of the Quaternion.

Returns
The X-Component of the imaginary part of the Quaternion

Definition at line 57 of file Quaternion.cpp.

◆ y()

biorbd::utils::Scalar biorbd::utils::Quaternion::y ( ) const

Return the Y-Component of the imaginary part of the Quaternion.

Returns
The Y-Component of the imaginary part of the Quaternion

Definition at line 61 of file Quaternion.cpp.

◆ z()

biorbd::utils::Scalar biorbd::utils::Quaternion::z ( ) const

Return the Z-Component of the imaginary part of the Quaternion.

Returns
The Z-Component of the imaginary part of the Quaternion

Definition at line 65 of file Quaternion.cpp.


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