Biorbd Release_1.13.0
Loading...
Searching...
No Matches
BIORBD_NAMESPACE::utils::Quaternion Class Reference

#include <Quaternion.h>

Inheritance diagram for BIORBD_NAMESPACE::utils::Quaternion:

Public Member Functions

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

Static Public Member Functions

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

Protected Attributes

utils::Scalar 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 25 of file Quaternion.h.

Constructor & Destructor Documentation

◆ Quaternion() [1/5]

utils::Quaternion::Quaternion ( const Scalar & kStabilizer = 1)

Construct Quaternion.

Parameters
kStabilizerThe value of the kstabilizer

Definition at line 17 of file Quaternion.cpp.

◆ Quaternion() [2/5]

utils::Quaternion::Quaternion ( const Quaternion & other)

Construct Quaternion from another quaternion.

Parameters
otherOther quaternion

Definition at line 20 of file Quaternion.cpp.

◆ Quaternion() [3/5]

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

Construct Quaternion.

Parameters
vec4The vector describing the quaternion
kStabilizerThe value of the kstabilizer

Definition at line 23 of file Quaternion.cpp.

◆ Quaternion() [4/5]

utils::Quaternion::Quaternion ( const Scalar & w,
const Scalar & x,
const Scalar & y,
const Scalar & z,
const Scalar & 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 28 of file Quaternion.cpp.

◆ Quaternion() [5/5]

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

Construct Quaternion.

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

Definition at line 36 of file Quaternion.cpp.

Member Function Documentation

◆ conjugate()

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

Return the conjugate of the quaternion.

Returns
The conjugate of the quaternion

Definition at line 242 of file Quaternion.cpp.

◆ derivate()

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

Return the time derivative of the quaterion.

Parameters
wThe vector of time derivative (output)

Definition at line 319 of file Quaternion.cpp.

◆ eulerDotToOmega()

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

Converts a 3d angular velocity vector.

Parameters
eulerDotthe Euler angle rates
eulerthe Euler angles
seqthe Euler angles sequence
Returns
a 3d vector of the body angular velocity

Definition at line 300 of file Quaternion.cpp.

◆ fromAxisAngle()

utils::Quaternion utils::Quaternion::fromAxisAngle ( const Scalar & angle,
const Vector3d & axis,
const Scalar & 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
Returns
The quaternion

Definition at line 116 of file Quaternion.cpp.

◆ fromGLRotate()

utils::Quaternion utils::Quaternion::fromGLRotate ( const Scalar & angle,
const Scalar & x,
const Scalar & y,
const Scalar & z,
const Scalar & 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
Returns
The quaternion

Definition at line 104 of file Quaternion.cpp.

◆ fromMatrix() [1/2]

utils::Quaternion utils::Quaternion::fromMatrix ( const Rotation & mat,
const Scalar & kStab = 1 )
static

Construct Quaternion from a Rotation matrix.

Parameters
matThe rotation matrix
kStabThe value of the kstabilizer
Returns
The quaternion

Definition at line 137 of file Quaternion.cpp.

◆ fromMatrix() [2/2]

utils::Quaternion utils::Quaternion::fromMatrix ( const RotoTrans & rt,
const Scalar & kStab = 1 )
static

Construct Quaternion from a RotoTrans matrix.

Parameters
rtRotoTrans matrix
kStabThe value of the kstabilizer
Returns
The quaternion

Definition at line 131 of file Quaternion.cpp.

◆ fromXYZAngles()

utils::Quaternion utils::Quaternion::fromXYZAngles ( const Vector3d & xyz_angles,
const Scalar & 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
Returns
The quaternion

Definition at line 165 of file Quaternion.cpp.

◆ fromYXZAngles()

utils::Quaternion utils::Quaternion::fromYXZAngles ( const Vector3d & yxz_angles,
const Scalar & 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
Returns
The quaternion

Definition at line 157 of file Quaternion.cpp.

◆ fromZYXAngles()

utils::Quaternion utils::Quaternion::fromZYXAngles ( const Vector3d & zyx_angles,
const Scalar & 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
Returns
The quaternion

Definition at line 149 of file Quaternion.cpp.

◆ kStab()

utils::Scalar 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 52 of file Quaternion.cpp.

◆ normalize()

void utils::Quaternion::normalize ( )

Force the normalization of the quaternion.

Definition at line 350 of file Quaternion.cpp.

◆ omegaToEulerDot()

utils::Vector3d utils::Quaternion::omegaToEulerDot ( const Vector3d & euler,
const Vector3d & w,
const String & seq )

converts a 3d vector of the body angular velocity (omega) into a 3d vector of the euler angles rate.

Parameters
eulerthe Euler angles
wthe body velocity (omega)
seqthe Euler angles sequence
Returns
a 3d vector of the euler angles rate

Definition at line 310 of file Quaternion.cpp.

◆ omegaToQuatDot()

utils::Quaternion utils::Quaternion::omegaToQuatDot ( const Vector3d & omega) const

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

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

Definition at line 265 of file Quaternion.cpp.

◆ operator*() [1/3]

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

Quaternion multiplication.

Parameters
otherThe other quaternion
Returns
The multiplied quaternion

Definition at line 54 of file Quaternion.cpp.

◆ operator*() [2/3]

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

Multiply the quaternion with a scalar.

Parameters
scalarThe scalar to multiply with
Returns
The multiplied quaternion

Definition at line 68 of file Quaternion.cpp.

◆ operator*() [3/3]

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

Multiply the quaternion with a scalar.

Parameters
scalarThe scalar to multiply with
Returns
The multiplied quaternion

Definition at line 75 of file Quaternion.cpp.

◆ operator+()

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

Add the quaternion to another.

Parameters
otherThe other quaternion to add
Returns
The added quaternion

Definition at line 90 of file Quaternion.cpp.

◆ operator-()

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

Subtract the quaternion to another.

Parameters
otherOther quaternion to substract
Returns
The subtracted quaternion

Definition at line 97 of file Quaternion.cpp.

◆ rotate()

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

Return a rotated vector from the quaternion.

Parameters
vecThe vector to rotate
Returns
The rotated vector

Definition at line 255 of file Quaternion.cpp.

◆ setKStab()

void utils::Quaternion::setKStab ( const Scalar & newKStab)

Set the k stabilizer.

Parameters
newKStabThe new value

Definition at line 48 of file Quaternion.cpp.

◆ slerp()

utils::Quaternion 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
Returns
The interpolated quaternion

Definition at line 200 of file Quaternion.cpp.

◆ timeStep()

utils::Quaternion utils::Quaternion::timeStep ( const Vector3d & omega,
const Scalar & 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 247 of file Quaternion.cpp.

◆ toMatrix()

utils::Rotation 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 173 of file Quaternion.cpp.

◆ velocityMatrix()

utils::Matrix3d utils::Quaternion::velocityMatrix ( const Vector3d & euler,
const String & seq )

Generate the velocity matrix which allows to go from/to euler angles to/from omega(body velocity).

Parameters
eulerthe Euler angles
seqthe Euler angles sequence
Returns
a 3d matrix

Definition at line 284 of file Quaternion.cpp.

◆ w()

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

Return the real part (w) the Quaternion.

Returns
The real part of the Quaternion

Definition at line 43 of file Quaternion.cpp.

◆ x()

utils::Scalar 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 44 of file Quaternion.cpp.

◆ y()

utils::Scalar 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 45 of file Quaternion.cpp.

◆ z()

utils::Scalar 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 46 of file Quaternion.cpp.

Member Data Documentation

◆ m_Kstab

utils::Scalar BIORBD_NAMESPACE::utils::Quaternion::m_Kstab
protected

Stabilization factor for the derivation.

Definition at line 351 of file Quaternion.h.


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