Description
template<class Real = double>
class chrono::ChQuaternion< Real >
Class defining quaternion objects, that is four-dimensional numbers.
Unit quaternions can be used to represent rotations in 3d (in which case, they are also known as "Euler parameters"). For more details, see the Quaternions manual page.
#include <ChQuaternion.h>
Public Member Functions | |
ChQuaternion () | |
Default constructor. More... | |
ChQuaternion (Real e0, Real e1, Real e2, Real e3) | |
Constructor from four scalars. More... | |
ChQuaternion (Real s, const ChVector3< Real > &v) | |
Constructor from real part, and vector with i,j,k imaginary part. | |
ChQuaternion (const ChQuaternion< Real > &other) | |
Copy constructor. | |
template<class RealB > | |
ChQuaternion (const ChQuaternion< RealB > &other) | |
Copy constructor with type change. | |
Real & | e0 () |
Access to components. | |
Real & | e1 () |
Real & | e2 () |
Real & | e3 () |
const Real & | e0 () const |
const Real & | e1 () const |
const Real & | e2 () const |
const Real & | e3 () const |
Real * | data () |
Access to underlying array storage. | |
const Real * | data () const |
template<typename Derived > | |
ChQuaternion (const Eigen::MatrixBase< Derived > &vec, typename std::enable_if<(Derived::MaxRowsAtCompileTime==1||Derived::MaxColsAtCompileTime==1), Derived >::type *=0) | |
Construct a quaternion from an Eigen vector expression. | |
Eigen::Map< Eigen::Matrix< Real, 4, 1 > > | eigen () |
View this quaternion as an Eigen vector. | |
Eigen::Map< const Eigen::Matrix< Real, 4, 1 > > | eigen () const |
template<typename Derived > | |
ChQuaternion & | operator= (const Eigen::MatrixBase< Derived > &vec) |
Assign an Eigen vector expression to this quaternion. | |
void | Set (Real e0, Real e1, Real e2, Real e3) |
Sets the four values of the quaternion at once. | |
void | Set (const ChQuaternion< Real > &q) |
Sets the quaternion as a copy of another quaternion. | |
void | Set (Real s) |
Sets the quaternion with four components as a sample scalar. | |
void | SetNull () |
Sets the quaternion as a null quaternion. | |
void | SetUnit () |
Sets the quaternion as a unit quaternion. | |
void | SetScalar (Real s) |
Sets the scalar part only. | |
void | SetVector (const ChVector3< Real > &v) |
Sets the vectorial part only. | |
bool | IsNull () const |
Return true if this quaternion is the null quaternion. | |
bool | IsIdentity () const |
Return true if this quaternion is the identity quaternion. | |
bool | Equals (const ChQuaternion< Real > &other) const |
Return true if quaternion is identical to other quaternion. | |
bool | Equals (const ChQuaternion< Real > &other, Real tol) const |
Return true if quaternion equals another quaternion, within a tolerance 'tol'. | |
ChVector3< Real > | GetVector () const |
Gets the vectorial part only. | |
ChVector3< Real > | GetAxisX () const |
Get the X axis of a coordinate system, given the quaternion which its alignment. More... | |
ChVector3< Real > | GetAxisY () const |
Get the Y axis of a coordinate system, given the quaternion which its alignment. More... | |
ChVector3< Real > | GetAxisZ () const |
Get the Z axis of a coordinate system, given the quaternion which its alignment. More... | |
Real | Length () const |
Compute the euclidean norm of the quaternion, that is its length or magnitude. | |
Real | Length2 () const |
Compute the squared euclidean norm of the quaternion. | |
Real | LengthInf () const |
Compute the infinity norm of the quaternion, that is the maximum absolute value of one of its elements. | |
Real & | operator[] (unsigned index) |
Subscript operator. | |
const Real & | operator[] (unsigned index) const |
ChQuaternion< Real > & | operator= (const ChQuaternion< Real > &other) |
Assignment operator: copy from another quaternion. | |
ChQuaternion< Real > | operator+ () const |
Operator for sign change. | |
ChQuaternion< Real > | operator- () const |
ChQuaternion< Real > | operator! () const |
Operator for making a conjugate quaternion (the original is not changed). More... | |
ChQuaternion< Real > | operator+ (const ChQuaternion< Real > &other) const |
Operator for quaternion sum. | |
ChQuaternion< Real > & | operator+= (const ChQuaternion< Real > &other) |
ChQuaternion< Real > | operator- (const ChQuaternion< Real > &other) const |
Operator for quaternion difference. | |
ChQuaternion< Real > & | operator-= (const ChQuaternion< Real > &other) |
ChQuaternion< Real > | operator* (const ChQuaternion< Real > &other) const |
Operator for quaternion product: A*B means the typical quaternion product. More... | |
ChQuaternion< Real > & | operator*= (const ChQuaternion< Real > &other) |
Operator for quaternion product and assignment: A*=B means A'=A*B, with typical quaternion product. More... | |
ChQuaternion< Real > | operator>> (const ChQuaternion< Real > &other) const |
Operator for 'specular' quaternion product: A>>B = B*A. More... | |
ChQuaternion< Real > & | operator>>= (const ChQuaternion< Real > &other) |
Operator for quaternion 'specular' product and assignment: A>>=B means A'=A>>B, or A'=B*A with typical quaternion product. More... | |
ChQuaternion< Real > | operator* (Real s) const |
ChQuaternion< Real > & | operator*= (Real s) |
ChQuaternion< Real > | operator/ (const ChQuaternion< Real > &other) const |
Operator for element-wise division. More... | |
ChQuaternion< Real > & | operator/= (const ChQuaternion< Real > &other) |
ChQuaternion< Real > | operator/ (Real s) const |
Operator for scaling the quaternion by inverse of a scalar value, as q/s. | |
ChQuaternion< Real > & | operator/= (Real s) |
Real | operator^ (const ChQuaternion< Real > &other) const |
Operator for dot product: A^B means the scalar dot-product A*B. More... | |
bool | operator<= (const ChQuaternion< Real > &other) const |
Component-wise comparison operators. | |
bool | operator>= (const ChQuaternion< Real > &other) const |
bool | operator< (const ChQuaternion< Real > &other) const |
bool | operator> (const ChQuaternion< Real > &other) const |
bool | operator== (const ChQuaternion< Real > &other) const |
bool | operator!= (const ChQuaternion< Real > &other) const |
void | Add (const ChQuaternion< Real > &A, const ChQuaternion< Real > &B) |
Set this quaternion to the sum of A and B: this = A + B. | |
void | Sub (const ChQuaternion< Real > &A, const ChQuaternion< Real > &B) |
Set this quaternion to the difference of A and B: this = A - B. | |
void | Cross (const ChQuaternion< Real > &qa, const ChQuaternion< Real > &qb) |
Set this quaternion to the quaternion product of the two quaternions A and B, following the classic Hamilton rule: this = AxB. More... | |
Real | Dot (const ChQuaternion< Real > &B) const |
Return the dot product with another quaternion: result = this ^ B. | |
void | Mul (const ChQuaternion< Real > &A, Real s) |
Set this quaternion to the product of a quaternion A and scalar s: this = A * s. | |
void | Scale (Real s) |
Scale this quaternion by a scalar: this *= s. | |
bool | Normalize () |
Normalize this quaternion in place, so that its euclidean length is 1. More... | |
ChQuaternion< Real > | GetNormalized () const |
Return a normalized copy of this quaternion, with euclidean length = 1. More... | |
void | Conjugate (const ChQuaternion< Real > &A) |
Set this quaternion to the conjugate of the A quaternion. | |
void | Conjugate () |
Conjugate this quaternion in place (its vectorial part changes sign). | |
ChQuaternion< Real > | GetConjugate () const |
Return a conjugated version of this quaternion. | |
ChQuaternion< Real > | GetInverse () const |
Return the inverse of this quaternion. | |
ChVector3< Real > | Rotate (const ChVector3< Real > &A) const |
Rotate the vector A on the basis of this quaternion: res=p*[0,A]*p' (speed-optimized version). More... | |
ChVector3< Real > | RotateBack (const ChVector3< Real > &A) const |
Rotate the vector A on the basis of conjugate of this quaternion: res=p'*[0,A]*p (speed-optimized version). More... | |
void | SetFromRotVec (const ChVector3< Real > &angle_axis) |
Set the quaternion from a rotation vector (ie. More... | |
ChVector3< Real > | GetRotVec () const |
Get the rotation vector (ie. More... | |
void | SetFromAngleAxis (Real angle, const ChVector3< Real > &axis) |
Set the quaternion from an angle of rotation and an axis, defined in absolute coords. More... | |
void | SetFromAngleX (Real angleX) |
Set the quaternion from an angle of rotation about X axis. | |
void | SetFromAngleY (Real angleY) |
Set the quaternion from an angle of rotation about Y axis. | |
void | SetFromAngleZ (Real angleZ) |
Set the quaternion from an angle of rotation about Z axis. | |
void | GetAngleAxis (Real &angle, ChVector3< Real > &axis) const |
Convert the quaternion to an angle of rotation and an axis, defined in absolute coords. More... | |
void | SetFromCardanAnglesZYX (const ChVector3< Real > &ang) |
Set the quaternion from Cardan angles ZYX (Tait-Bryan sequence Z-Y'-X'', intrinsic rotations). More... | |
ChVector3< Real > | GetCardanAnglesZYX () const |
Convert the quaternion to Cardan angles ZYX (Tait-Bryan sequence Z-Y'-X'', intrinsic rotations). More... | |
void | SetFromCardanAnglesXYZ (const ChVector3< Real > &ang) |
Set the quaternion from Cardan angles XYZ (Tait-Bryan sequence X-Y'-Z'', intrinsic rotations). | |
ChVector3< Real > | GetCardanAnglesXYZ () const |
Convert the quaternion to Cardan angles XYZ (Tait-Bryan sequence X-Y'-Z'', intrinsic rotations). | |
void | SetDtFromAngVelAbs (const ChVector3< Real > &w, const ChQuaternion< Real > &q) |
Set the quaternion dq/dt. More... | |
void | SetDtFromAngVelRel (const ChVector3< Real > &w, const ChQuaternion< Real > &q) |
Set the quaternion dq/dt. More... | |
void | GetAngVelAbs (ChVector3< Real > &w, const ChQuaternion< Real > &q) |
Compute the vector of angular speed 'w' specified in absolute coords, from this quaternion dq/dt and the rotation expressed as a quaternion q. | |
void | GetAngVelRel (ChVector3< Real > &w, const ChQuaternion< Real > &q) |
Compute the vector of angular speed 'w' specified in relative coords, from this quaternion dq/dt and the rotation expressed as a quaternion q. | |
void | SetDt2FromAngAccAbs (const ChVector3< Real > &a, const ChQuaternion< Real > &q, const ChQuaternion< Real > &q_dt) |
Set the quaternion ddq/dtdt. More... | |
void | SetDt2FromAngAccRel (const ChVector3< Real > &a, const ChQuaternion< Real > &q, const ChQuaternion< Real > &q_dt) |
Set the quaternion ddq/dtdt. More... | |
void | SetDtFromAngleAxis (const ChQuaternion< Real > &q, Real angle_dt, const ChVector3< Real > &axis) |
Set the quaternion dq/dt. More... | |
void | SetDt2FromAngleAxis (const ChQuaternion< Real > &q, const ChQuaternion< Real > &q_dt, Real angle_dtdt, const ChVector3< Real > &axis) |
Set the quaternion ddq/dtdt. More... | |
void | ArchiveOut (ChArchiveOut &archive_out) |
Method to allow serialization of transient m_data to archives. | |
void | ArchiveIn (ChArchiveIn &archive_in) |
Method to allow de-serialization of transient m_data from archives. | |
Friends | |
template<typename RealB > | |
class | ChQuaternion |
Constructor & Destructor Documentation
◆ ChQuaternion() [1/2]
|
inline |
Default constructor.
Note that this constructs a null quaternion {0,0,0,0}, not a {1,0,0,0} unit quaternion.
◆ ChQuaternion() [2/2]
|
inline |
Constructor from four scalars.
The first is the real part, others are i,j,k imaginary parts
Member Function Documentation
◆ Cross()
|
inline |
Set this quaternion to the quaternion product of the two quaternions A and B, following the classic Hamilton rule: this = AxB.
This is the true, typical quaternion product. It is NOT commutative.
◆ GetAngleAxis()
|
inline |
Convert the quaternion to an angle of rotation and an axis, defined in absolute coords.
Resulting angle and axis must be passed as parameters. Note that angle is in [-PI....+PI] range. Also remember (angle, axis) is the same of (-angle,-axis). If you need directly the rotation vector=axis * angle, use GetRotVec().
◆ GetAxisX()
|
inline |
Get the X axis of a coordinate system, given the quaternion which its alignment.
It is assumed that the quaternion is normalized (and thus represents a rotation).
◆ GetAxisY()
|
inline |
Get the Y axis of a coordinate system, given the quaternion which its alignment.
It is assumed that the quaternion is normalized (and thus represents a rotation).
◆ GetAxisZ()
|
inline |
Get the Z axis of a coordinate system, given the quaternion which its alignment.
It is assumed that the quaternion is normalized (and thus represents a rotation).
◆ GetCardanAnglesZYX()
|
inline |
Convert the quaternion to Cardan angles ZYX (Tait-Bryan sequence Z-Y'-X'', intrinsic rotations).
NASA angles (heading, bank, attitude).
◆ GetNormalized()
|
inline |
Return a normalized copy of this quaternion, with euclidean length = 1.
Not to be confused with Normalize() which normalizes in place.
◆ GetRotVec()
|
inline |
Get the rotation vector (ie.
a 3D axis of rotation with length as angle of rotation) from a quaternion. If you need distinct axis and angle, use GetAngleAxis().
◆ Normalize()
|
inline |
Normalize this quaternion in place, so that its euclidean length is 1.
Return false if the original quaternion had zero length (in which case the quaternion is set to [1,0,0,0]) and return true otherwise.
◆ operator!()
|
inline |
Operator for making a conjugate quaternion (the original is not changed).
A conjugate quaternion has the vectorial part with changed sign.
◆ operator*()
|
inline |
Operator for quaternion product: A*B means the typical quaternion product.
Notes:
- since unit quaternions can represent rotations, the product can represent a concatenation of rotations as: frame_rotation_2to0 = frame_rotation_1to0 * frame_rotation_2to1
- pay attention to operator low precedence (see C++ precedence rules!)
- quaternion product is not commutative.
◆ operator*=()
|
inline |
Operator for quaternion product and assignment: A*=B means A'=A*B, with typical quaternion product.
Notes:
- since unit quaternions can represent rotations, the product can represent a post-concatenation of a rotation in a kinematic chain.
- quaternion product is not commutative.
◆ operator/()
|
inline |
Operator for element-wise division.
Note that this is NOT the quaternion division operation.
◆ operator>>()
|
inline |
Operator for 'specular' quaternion product: A>>B = B*A.
Notes:
- since unit quaternions can represent rotations, the product can represent a concatenation of rotations as: frame_rotation_2to0 = frame_rotation_2to1 >> frame_rotation_1to0
- pay attention to operator low precedence (see C++ precedence rules!)
- quaternion product is not commutative.
◆ operator>>=()
|
inline |
Operator for quaternion 'specular' product and assignment: A>>=B means A'=A>>B, or A'=B*A with typical quaternion product.
Notes:
- since unit quaternions can represent rotations, the product can represent a pre-concatenation of a rotation in a kinematic chain.
- quaternion product is not commutative.
◆ operator^()
|
inline |
Operator for dot product: A^B means the scalar dot-product A*B.
Note: pay attention to operator low precedence (see C++ precedence rules!)
◆ Rotate()
|
inline |
Rotate the vector A on the basis of this quaternion: res=p*[0,A]*p' (speed-optimized version).
Endomorphism assumes p is already normalized.
◆ RotateBack()
|
inline |
Rotate the vector A on the basis of conjugate of this quaternion: res=p'*[0,A]*p (speed-optimized version).
Endomorphism assumes p is already normalized.
◆ SetDt2FromAngAccAbs()
|
inline |
Set the quaternion ddq/dtdt.
Inputs: the vector of angular acceleration 'a' specified in absolute coords, the rotation expressed as a quaternion q, the rotation speed as a quaternion 'q_dt'.
◆ SetDt2FromAngAccRel()
|
inline |
Set the quaternion ddq/dtdt.
Inputs: the vector of angular acceleration 'a' specified in relative coords, the rotation expressed as a quaternion q, the rotation speed as a quaternion 'q_dt'.
◆ SetDt2FromAngleAxis()
|
inline |
Set the quaternion ddq/dtdt.
Inputs: the axis of ang. acceleration 'axis' (assuming it is already normalized and expressed in absolute coords), the angular acceleration 'angle_dtdt' (scalar value), the rotation expressed as a quaternion 'quat' and th rotation speed 'q_dt'.
◆ SetDtFromAngleAxis()
|
inline |
Set the quaternion dq/dt.
Inputs: the axis of rotation 'axis' (assuming it is already normalized and expressed in absolute coords), the angular speed 'angle_dt' (scalar value), and the rotation expressed as a quaternion 'q'.
◆ SetDtFromAngVelAbs()
|
inline |
Set the quaternion dq/dt.
Inputs: the vector of angular speed w specified in absolute coords, and the rotation expressed as a quaternion q.
◆ SetDtFromAngVelRel()
|
inline |
Set the quaternion dq/dt.
Inputs: the vector of angular speed w specified in relative coords, and the rotation expressed as a quaternion q.
◆ SetFromAngleAxis()
|
inline |
Set the quaternion from an angle of rotation and an axis, defined in absolute coords.
The axis is supposed to be fixed, i.e. it is constant during rotation! NOTE, axis must be normalized! If you need directly the rotation vector=axis * angle, use SetFromRotVec().
◆ SetFromCardanAnglesZYX()
|
inline |
Set the quaternion from Cardan angles ZYX (Tait-Bryan sequence Z-Y'-X'', intrinsic rotations).
NASA angles (heading, bank, attitude).
◆ SetFromRotVec()
|
inline |
Set the quaternion from a rotation vector (ie.
a 3D axis of rotation with length as angle of rotation) defined in absolute coords. If you need distinct axis and angle, use SetFromAngleAxis().
The documentation for this class was generated from the following file:
- /builds/uwsbel/chrono/src/chrono/core/ChQuaternion.h