Template Class quaternion_type

Class Documentation

template<typename T>
class quaternion_type

A stripped down quaternion implementation, based on boost::math::quaternion.

We use quaternions to do rotations in 3d space. Quaternions are faster than matrix calculations and they also suffer less from drift caused by rounding errors.

Like complex number, quaternions do have a meaningful notion of “real part”, but unlike them there is no meaningful notion of “imaginary part”. Instead there is an “unreal part” which itself is a quaternion, and usually nothing simpler (as opposed to the complex number case). However, for practicality, there are accessors for the other components (these are necessary for the templated copy constructor, for instance).

Note

Quaternion multiplication is NOT commutative; symbolically, “q *= rhs;” means “q = q * rhs;” and “q /= rhs;” means “q = q * inverse_of(rhs);”

Public Types

using value_type = T

the value type of the elements, usually this is float

Public Functions

inline explicit constexpr quaternion_type(value_type const &value_a = {}, value_type const &value_b = {}, value_type const &value_c = {}, value_type const &value_d = {})

constructor with the four members

inline explicit constexpr quaternion_type(std::complex<value_type> const &z0, std::complex<value_type> const &z1 = std::complex<value_type>())

constructor taking two complex values as input

constexpr quaternion_type(quaternion_type const&) = default

Copy constructor.

constexpr quaternion_type(quaternion_type&&) = default

Copy constructor.

template<typename X>
inline explicit constexpr quaternion_type(quaternion_type<X> const &rhs)

Copy constructor accepting a quaternion with a different value_type.

inline constexpr value_type real() const

See class description, return the real part of the quaternion.

inline constexpr quaternion_type unreal() const

See class description, return the unreal part of the quaternion.

inline constexpr void swap(quaternion_type &o)

swap

template<typename X>
inline constexpr quaternion_type &operator=(quaternion_type<X> const &rhs)

Assignment operator accepting a quaternion with optionally another value_type.

inline constexpr quaternion_type &operator=(quaternion_type const &rhs)

Assignment operator.

inline constexpr quaternion_type &operator=(value_type const &rhs)

Assignment operator that sets the real part to rhs and the unreal parts to zero.

inline constexpr quaternion_type &operator=(std::complex<value_type> const &rhs)

Assignment operator that sets the real part to the real part of rhs and the first unreal part to the imaginary part of of rhs. The other unreal

inline constexpr quaternion_type &operator+=(value_type const &rhs)

operator += adding value rhs to the real part

inline constexpr quaternion_type &operator+=(std::complex<value_type> const &rhs)

operator += adding the real part of rhs to the real part and the imaginary part of rhs to the first unreal part

template<class X>
inline constexpr quaternion_type &operator+=(quaternion_type<X> const &rhs)

operator += adding the parts of rhs to the equivalent part of this

inline constexpr quaternion_type &operator-=(value_type const &rhs)

operator -= subtracting value rhs from the real part

inline constexpr quaternion_type &operator-=(std::complex<value_type> const &rhs)

operator -= subtracting the real part of rhs from the real part and the imaginary part of rhs from the first unreal part

template<class X>
inline constexpr quaternion_type &operator-=(quaternion_type<X> const &rhs)

operator -= subtracting the parts of rhs from the equivalent part of this

inline constexpr quaternion_type &operator*=(value_type const &rhs)

multiply all parts with value rhs

inline constexpr quaternion_type &operator*=(std::complex<value_type> const &rhs)

multiply with complex number rhs

template<typename X>
inline constexpr quaternion_type &operator*=(quaternion_type<X> const &rhs)

multiply with quaternion rhs

inline constexpr quaternion_type &operator/=(value_type const &rhs)

divide all parts by rhs

inline constexpr quaternion_type &operator/=(std::complex<value_type> const &rhs)

divide by complex number rhs

template<typename X>
inline constexpr quaternion_type &operator/=(quaternion_type<X> const &rhs)

divide by quaternion rhs

inline constexpr value_type get_a() const

Return part a.

inline constexpr value_type get_b() const

Return part b.

inline constexpr value_type get_c() const

Return part c.

inline constexpr value_type get_d() const

Return part d.

inline constexpr bool operator==(const quaternion_type &rhs) const

compare with rhs

inline constexpr bool operator!=(const quaternion_type &rhs) const

compare with rhs

inline constexpr operator bool() const

test for all zero values

Friends

inline friend constexpr friend quaternion_type operator* (const quaternion_type &a, const quaternion_type &b)

multiply a with b and return the result

inline friend constexpr friend quaternion_type normalize (quaternion_type q)

normalise the values so that the length of the result is exactly 1

inline friend constexpr friend quaternion_type conj (quaternion_type q)

return the conjugate of this