Class Quaternion
-
template<typename T, QType B = Unitary>
class Quaternion Represents either a left-handed quaternion or a biquaternion.
The Quaternion template class was designed to represent either biquaternions (a quaternion with complex-valued coefficients) or left-handed quaternions using the Pauli spin matrices as the basis (see below).
Left-handed quaternions can have either purely imaginary (QType = Unitary) or purely real (QType = Hermitian) vector components. However, as the product of two Hermitian matrices is not Hermitian (unless the matrices commute), it is not possible to multiply two real quaternions in the Pauli basis.
There are four ways to create a null-constructed instance of a Quaternion object:
// Left-handed quaternion (unitary basis) Quaternion<float> q; // Representation of Hermitian matrix (non-multiplicative) Quaternion<float, Hermitian> h; // Biquaternion in unitary basis Quaternion<complex<float>, Unitary> bq; // Biquaternion in Hermitian basis Quaternion<complex<float>, Hermitian> bh;
Note that the floating-point precision is specified in the first template argument and the type, Unitary or Hermitian, is specified in the second template argument. As the left-handed quaternion is most closely related to Hamilton’s quaternion, the Unitary basis is used by default.
A biquaternion may be represented by the linear combination,
\[ \bm{B}=b_0\pauli{0}+b_1\pauli{1}+b_2\pauli{2}+b_3\pauli{3},\hspace{5mm}b_i\in\C \]where \(\pauli{0}\) is the identity matrix and \(\pauli{1-3}\) are the Pauli spin matrices. The Pauli matrices have the following properties:\[ \pauli{i}^2 = \bm{I}, \hspace{5mm} \pauli{i}\pauli{j} = -\pauli{j}\pauli{i} = \Ci\pauli{k} \]where \(\{i,j,k\}\) is chosen from cyclic permutations of \(\{1,2,3\}\).A biquaternion may be written as a scalar plus a three-vector:
\[ \bm{B}=[b+\bm{b}] = b\pauli{0} + \bm{b\cdot\sigma}, \hspace{5mm} b_i\in\C \]where \(\bm{b}=(b_1,b_2,b_3)\) and \(\bm{\sigma}\) is a three-vector whose components are the Pauli spin matrices. Using this notation, the left-handed quaternion sub-group may be represented as\[ \bm{Q}=[q+i\bm{q}]= q\pauli{0} + \Ci\bm{q\cdot\sigma}, \hspace{5mm} q_i\in\R. \]Consider the product of two biquaternions, \(\bm{A}=[a_0+\bm{a}]\) and \(\bm{B}=[b_0+\bm{b}]\),
\[\begin{split} \begin{array}{ccl} \bm{A}\bm{B} & = & (a_0\pauli{0} + a_1\pauli{1} + a_2\pauli{2} + a_3\pauli{3}) (b_0\pauli{0} + b_1\pauli{1} + b_2\pauli{2} + b_3\pauli{3}) \\ & = & a_0b_0\pauli{0}\pauli{0} + a_0b_1\pauli{0}\pauli{1} + a_0b_2\pauli{0}\pauli{2} + a_0b_3\pauli{0}\pauli{3} \\ & + & a_1b_0\pauli{1}\pauli{0} + a_1b_1\pauli{1}\pauli{1} + a_1b_2\pauli{1}\pauli{2} + a_1b_3\pauli{1}\pauli{3} \\ & + & a_2b_0\pauli{2}\pauli{0} + a_2b_1\pauli{2}\pauli{1} + a_2b_2\pauli{2}\pauli{2} + a_2b_3\pauli{2}\pauli{3} \\ & + & a_3b_0\pauli{3}\pauli{0} + a_3b_1\pauli{3}\pauli{1} + a_3b_2\pauli{3}\pauli{2} + a_3b_3\pauli{3}\pauli{3} \end{array} \end{split}\]which reduces to\[\begin{split} \begin{array}{ccl} \bm{A}\bm{B} & = & (a_0b_0 + a_1b_1 + a_2b_2 + a_3b_3) \pauli{0} \\ & + & (a_0b_1 + a_1b_0 + \Ci a_2b_3 - \Ci a_3b_2) \pauli{1} \\ & + & (a_0b_2 - \Ci a_1b_3 + a_2b_0 + \Ci a_3b_1) \pauli{2} \\ & + & (a_0b_3 + \Ci a_1b_2 - \Ci a_2b_1 + a_3b_0) \pauli{3} \end{array} \end{split}\]This equation is used to derive the multiplication rule for left-handed quaternions. Assuming that \(\bm{C}=[c_0+\Ci\bm{c}]\) and \(\bm{D}=[d_0+\Ci\bm{d}]\), the left-handed quaternion product, \(\bm{X}=[x_0+\Ci\bm{x}]=\bm{CD}\), is given by
\[\begin{split} \begin{array}{rl} x_0 & = c_0d_0 - c_1d_1 - c_2d_2 - c_3d_3 \\ x_1 & = c_0d_1 + c_1d_0 - c_2d_3 + c_3d_2 \\ x_2 & = c_0d_2 + c_1d_3 + c_2d_0 - c_3d_1 \\ x_3 & = c_0d_3 - c_1d_2 + c_2d_1 + c_3d_0 \end{array} \end{split}\]Notice that this result differs from the product of two quaternions as originally defined by Hamilton. This is because the left-handed quaternion basis is given by the Pauli spin matrices multiplied by the imaginary number, \(\Ci=\sqrt{-1}\), which satisfy
\[ \Ci\pauli{i} \Ci\pauli{j} = -\Ci\pauli{k} \]Public Functions
-
inline Quaternion(const T &a = 0.0, const T &b = 0.0, const T &c = 0.0, const T &d = 0.0)
Default constructor.
-
template<typename U>
inline Quaternion(T s, const Vector<3, U> &v) Construct from a scalar and vector.
-
template<typename U>
inline Quaternion(const Quaternion<U, B> &s) Construct from another Quaternion
-
template<typename U>
inline const Quaternion &operator=(const Quaternion<U, B> &s) Set this instance equal to another Quaternion
-
inline const Quaternion &operator+=(const T &s)
Scalar addition.
-
inline const Quaternion &operator-=(const T &s)
Scalar subtraction.
-
inline const Quaternion &operator*=(const T &a)
Scalar multiplication.
-
inline const Quaternion &operator/=(const T &a)
Scalar division.
-
template<class U>
inline const Quaternion &operator+=(const Quaternion<U, B> &s) Quaternion addition.
-
template<class U>
inline const Quaternion &operator-=(const Quaternion<U, B> &s) Quaternion subtraction.
-
template<class U>
inline const Quaternion &operator*=(const Quaternion<U, B> &s) Quaternion multiplication.
-
inline bool operator==(const Quaternion &b) const
Equality.
-
inline bool operator!=(const Quaternion &b) const
Inequality.
-
inline unsigned size() const
Dimension of data.
Public Static Functions
-
static const Quaternion &identity()
Identity.
The identity Quaternion.
Friends
-
inline friend Quaternion operator-(Quaternion s)
Negation.
-
inline Quaternion(const T &a = 0.0, const T &b = 0.0, const T &c = 0.0, const T &d = 0.0)