Quaternion Class¶
-
class QDynamics::Quaternion : public JSL::Vector¶
A computational replica of the mathematical object quaternion, which replicates the expected behaviour of such objects, including addition and scalar multiplication (which it inherits from JSL::Vector() ), as well as the idiosyncratic multiplication and division native ot this field. We use the notation that \(\mathsf{q} = (q_0, \vec{q})\) , and the interface is based on this assumption. It is intentional that treating quaternions as members of \(\mathbb{R}^4\) is awkward.
Public Functions
-
inline double &Scalar()¶
The current value of the Scalar component, returned as a reference. This allows it to be assigned to: q.Scalar() = x stores the value of x in the scalar component.
- Returns
A reference to the scalar component of the quaternion
-
inline double &Vector(int i)¶
The current value of the ith Vector component, returned as a reference. This allows it to be assigned to: q.Vector(i) = x stores the value of x in the scalar component.
- Returns
A reference to the ith vector component of the quaternion
-
inline JSL::Vector Vector() const¶
The current value of the Vector component. This cannot be modified in-place or assigned to as Vector(int i) and Scalar() can be.
- Returns
A JSL::Vector object containing the Vector portion of the quaternion.
-
inline Quaternion()¶
Default initialiser. Initialises to.
\(\mathsf{q} = (0, \vec{0})\)
-
inline Quaternion(const double &q0, const JSL::Vector &qVec)¶
Initialises the object to.
\(\mathsf{q} = (q_0, \vec{q})\)
- Parameters
q0 – The value \(q_0\)
qVec – The value \(\vec{q}\) . This must be a vector of length 3, or an error is thrown.
-
inline Quaternion(const double &a, const double &b, const double &c, const double &d)¶
Initialises the object to the value.
\(\mathsf{q} = \left(a, \begin{pmatrix} b \\ c \\ d \end{pmatrix}\right)\)
- Parameters
a – The scalar value of the quaternion
b – The x-component of the vector
c – The y-component of the vector
d – The z-component of the vector
-
inline Quaternion(const JSL::Vector &vec4)¶
Initialises the quaternion as if it were a member of R^4.
- Parameters
vec4 – A JSL::Vector object of length 4 (else an error is thrown)
-
inline Quaternion(const std::vector<double> &vec4)¶
Initialises the quaternion as if it were a member of R^4.
- Parameters
vec4 – A std::vector<double> object of length 4 (else an error is thrown)
-
inline Quaternion Conjugate() const¶
Returns the conjugate of the current quaternion.
- Returns
The value \(\overline{\mathsf{q}} = (q_0, -\vec{q})\)
-
inline JSL::Matrix LeftMultiplicationMatrix() const¶
Constructs a matrix L(q) such that L(q) b = q*b, replacing the usual quaternion multiplication operation operator*(const Quaternion & lhs, const Quaternion & rhs)
- Returns
The JSL::Matrix object which performs the multiplication
-
inline JSL::Matrix RightMultiplicationMatrix() const¶
Constructs a matrix R(q) such that R(q) b = b*q, replacing the usual quaternion multiplication operation operator*(const Quaternion & lhs, const Quaternion & rhs)
- Returns
The JSL::Matrix object which performs the multiplication
-
inline const double &Scalar() const¶
An annoying double-definition of Scalar(), required for when the quaternion object is a const (and hence the references need to be carefully guarded)
-
inline const double &Vector(int id) const¶
An annoying double-definition of Scalar(int i), required for when the quaternion object is a const (and hence the references need to be carefully guarded)
Public Static Functions
-
static inline Quaternion One()¶
A static constructor which returns the multiplicative identity.
\(\mathsf{q} = \left(1, \vec{0}\right)\)
-
static inline Quaternion Zero()¶
A static constructor which returns the additive identity.
\(\mathsf{q} = \left(0, \vec{0}\right)\) . Nominally unneeded, as the default constructor also returns 0, but this is itself based on the default constructor of the JSL::Vector object. To avoid potential future errors, the Zero() function is safer!
-
static inline Quaternion Random()¶
Generates a quaternion which is randomly populated with values between 0 and 1.
-
inline double &Scalar()¶