[nnm] No Nonsense Math 0.5.0
A No-Nonsense, C++ 17, single-header-only Math library geared towards graphics programming.
Loading...
Searching...
No Matches
nnm::Quaternion< Real > Class Template Reference

#include <nnm.hpp>

Public Member Functions

constexpr Quaternion ()
template<typename Other>
constexpr Quaternion (const Quaternion< Other > &quaternion)
constexpr Quaternion (const Vector4< Real > &vector)
constexpr Quaternion (const Real x, const Real y, const Real z, const Real w)
Quaternion normalize () const
Vector3< Real > axis_to (const Quaternion &to) const
Real angle_to (const Quaternion &to) const
Vector3< Real > axis () const
Real angle () const
constexpr Quaternion inverse () const
constexpr Real length_sqrd () const
Real length () const
Quaternion slerp (const Quaternion &to, const Real weight) const
Quaternion rotate_axis_angle (const Vector3< Real > &axis, const Real angle) const
constexpr Quaternion rotate_quaternion (const Quaternion &by) const
constexpr bool approx_equal (const Quaternion &other) const
constexpr const Real & at (const uint8_t index) const
constexpr Real & at (const uint8_t index)
constexpr const Real & operator[] (const uint8_t index) const
constexpr Real & operator[] (const uint8_t index)
constexpr bool operator== (const Quaternion &other) const
constexpr bool operator!= (const Quaternion &other) const
constexpr Quaternion operator* (const Quaternion &other) const
constexpr Quaternionoperator*= (const Quaternion &other)
constexpr bool operator< (const Quaternion &other) const
constexpr operator bool () const

Static Public Member Functions

static constexpr Quaternion identity ()
static Quaternion from_axis_angle (const Vector3< Real > &axis, const Real angle)
static Quaternion from_vector_to_vector (const Vector3< Real > &from, const Vector3< Real > &to)

Public Attributes

Real x
Real y
Real z
Real w

Detailed Description

template<typename Real>
class nnm::Quaternion< Real >

Quaternion which is a four-component vector that represents rotations in three-dimensional space.

Template Parameters
RealFloating-point value.

Constructor & Destructor Documentation

◆ Quaternion() [1/4]

template<typename Real>
nnm::Quaternion< Real >::Quaternion ( )
inlineconstexpr

Initialize with quaternion identity.

◆ Quaternion() [2/4]

template<typename Real>
template<typename Other>
nnm::Quaternion< Real >::Quaternion ( const Quaternion< Other > & quaternion)
inlineexplicitconstexpr

Cast from another quaternion type.

Template Parameters
OtherOther type.
Parameters
quaternionQuaternion to cast from.

◆ Quaternion() [3/4]

template<typename Real>
nnm::Quaternion< Real >::Quaternion ( const Vector4< Real > & vector)
inlineexplicitconstexpr

Initialize from a four-dimensional vector. No normalization is done.

Parameters
vectorVector.

◆ Quaternion() [4/4]

template<typename Real>
nnm::Quaternion< Real >::Quaternion ( const Real x,
const Real y,
const Real z,
const Real w )
inlineconstexpr

Initialize with components. No normalization is done.

Parameters
xX value.
yY value.
zZ value.
wW value.

Member Function Documentation

◆ angle()

template<typename Real>
Real nnm::Quaternion< Real >::angle ( ) const
inlinenodiscard

The angle of rotation of the quaternion in radians.

Returns
Resulting angle in radians.

◆ angle_to()

template<typename Real>
Real nnm::Quaternion< Real >::angle_to ( const Quaternion< Real > & to) const
inlinenodiscard

Angle of rotation, in radians, between this quaternion and another quaternion.

Parameters
toQuaternion to.
Returns
Resulting angle in radians.

◆ approx_equal()

template<typename Real>
bool nnm::Quaternion< Real >::approx_equal ( const Quaternion< Real > & other) const
inlinenodiscardconstexpr

Component-wise equality.

Parameters
otherOther quaternion.
Returns
True if approximately equal, false otherwise.

◆ at() [1/2]

template<typename Real>
Real & nnm::Quaternion< Real >::at ( const uint8_t index)
inlineconstexpr

Reference to component at index.

Parameters
indexIndex.
Returns
Reference.

◆ at() [2/2]

template<typename Real>
const Real & nnm::Quaternion< Real >::at ( const uint8_t index) const
inlinenodiscardconstexpr

Constant reference to component at index.

Parameters
indexIndex.
Returns
Constant reference.

◆ axis()

template<typename Real>
Vector3< Real > nnm::Quaternion< Real >::axis ( ) const
inlinenodiscard

The axis of rotation of the quaternion.

Returns
Resulting normalized axis.

◆ axis_to()

template<typename Real>
Vector3< Real > nnm::Quaternion< Real >::axis_to ( const Quaternion< Real > & to) const
inlinenodiscard

The normalized axis of rotation between this quaternion and another quaternion.

Parameters
toQuaternion to.
Returns
Resulting normalized, three-dimensional axis.

◆ from_axis_angle()

template<typename Real>
Quaternion nnm::Quaternion< Real >::from_axis_angle ( const Vector3< Real > & axis,
const Real angle )
inlinestaticnodiscard

Quaternion from a normalized axis and angle in radians.

Parameters
axisNormalized axis.
angleAngle in radians.
Returns
Result.

◆ from_vector_to_vector()

template<typename Real>
Quaternion nnm::Quaternion< Real >::from_vector_to_vector ( const Vector3< Real > & from,
const Vector3< Real > & to )
inlinestaticnodiscard

Quaternion that represents the rotation required to align one vector in the direction of another vector.

Parameters
fromVector from.
toVector to.
Returns
Result.

◆ identity()

template<typename Real>
constexpr Quaternion nnm::Quaternion< Real >::identity ( )
inlinestaticnodiscardconstexpr

Quaternion identity which is x, y, and z being zero and w being one.

Returns
Result.

◆ inverse()

template<typename Real>
Quaternion nnm::Quaternion< Real >::inverse ( ) const
inlinenodiscardconstexpr

Quaternion inverse.

Returns
Result.

◆ length()

template<typename Real>
Real nnm::Quaternion< Real >::length ( ) const
inlinenodiscard

Length of quaternion.

Returns
Result.

◆ length_sqrd()

template<typename Real>
Real nnm::Quaternion< Real >::length_sqrd ( ) const
inlinenodiscardconstexpr

Squared length of quaternion.

Returns
Result.

◆ normalize()

template<typename Real>
Quaternion nnm::Quaternion< Real >::normalize ( ) const
inlinenodiscard

Normalize quaternion.

Returns
Result.

◆ operator bool()

template<typename Real>
nnm::Quaternion< Real >::operator bool ( ) const
inlineexplicitnodiscardconstexpr

Evaluates to false if all components are zero, true otherwise.

◆ operator!=()

template<typename Real>
bool nnm::Quaternion< Real >::operator!= ( const Quaternion< Real > & other) const
inlinenodiscardconstexpr

Component-wise inequality.

Parameters
otherOther quaternion.
Returns
True if unequal, false otherwise.

◆ operator*()

template<typename Real>
Quaternion nnm::Quaternion< Real >::operator* ( const Quaternion< Real > & other) const
inlinenodiscardconstexpr

Quaternion multiplication.

Parameters
otherOther quaternion.
Returns
Result.

◆ operator*=()

template<typename Real>
Quaternion & nnm::Quaternion< Real >::operator*= ( const Quaternion< Real > & other)
inlineconstexpr

Quaternion multiplication.

Parameters
otherOther quaternion.
Returns
Reference to this modified quaternion.

◆ operator<()

template<typename Real>
bool nnm::Quaternion< Real >::operator< ( const Quaternion< Real > & other) const
inlinenodiscardconstexpr

Lexicographical comparison between components.

Parameters
otherOther quaternion.
Returns
True if less than, false otherwise.

◆ operator==()

template<typename Real>
bool nnm::Quaternion< Real >::operator== ( const Quaternion< Real > & other) const
inlinenodiscardconstexpr

Component-wise equality.

Parameters
otherOther quaternion.
Returns
True if equal, false otherwise.

◆ operator[]() [1/2]

template<typename Real>
Real & nnm::Quaternion< Real >::operator[] ( const uint8_t index)
inlinenodiscardconstexpr

Reference to component at index.

Parameters
indexIndex.
Returns
Result.

◆ operator[]() [2/2]

template<typename Real>
const Real & nnm::Quaternion< Real >::operator[] ( const uint8_t index) const
inlinenodiscardconstexpr

Constant reference to component at index.

Parameters
indexIndex.
Returns
Result.

◆ rotate_axis_angle()

template<typename Real>
Quaternion nnm::Quaternion< Real >::rotate_axis_angle ( const Vector3< Real > & axis,
const Real angle ) const
inlinenodiscard

Rotate about a normalized axis and angle in radians.

Parameters
axisNormalized axis.
angleAngle in radians.
Returns
Result.

◆ rotate_quaternion()

template<typename Real>
Quaternion nnm::Quaternion< Real >::rotate_quaternion ( const Quaternion< Real > & by) const
inlinenodiscardconstexpr

Rotate by another quaternion.

Parameters
byQuaternion to rotate by.
Returns
Result.

◆ slerp()

template<typename Real>
Quaternion nnm::Quaternion< Real >::slerp ( const Quaternion< Real > & to,
const Real weight ) const
inlinenodiscard

Spherical linear interpolation from one quaternion to another.

Parameters
toQuaternion to interpolate to.
weightInterpolate weight typically from zero to one.
Returns
Result.

Member Data Documentation

◆ w

template<typename Real>
Real nnm::Quaternion< Real >::w

◆ x

template<typename Real>
Real nnm::Quaternion< Real >::x

◆ y

template<typename Real>
Real nnm::Quaternion< Real >::y

◆ z

template<typename Real>
Real nnm::Quaternion< Real >::z

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