MeshLib
 
Loading...
Searching...
No Matches
MR::Quaternion< T > Struct Template Reference

#include <MRQuaternion.h>

Public Member Functions

constexpr Quaternion () noexcept=default
 
constexpr Quaternion (T a, T b, T c, T d) noexcept
 
constexpr Quaternion (const Vector3< T > &axis, T angle) noexcept
 
constexpr Quaternion (T real, const Vector3< T > &im) noexcept
 
constexpr Quaternion (const Matrix3< T > &m)
 
constexpr Quaternion (const Vector3< T > &from, const Vector3< T > &to) noexcept
 finds shorter arc rotation quaternion from one vector to another
 
constexpr Vector3< T > im () const noexcept
 returns imaginary part of the quaternion as a vector
 
constexpr T angle () const noexcept
 returns angle of rotation encoded in this quaternion
 
constexpr Vector3< T > axis () const noexcept
 returns axis of rotation encoded in this quaternion
 
constexpr T normSq () const
 
constexpr T norm () const
 
constexpr Quaternion operator- () const
 returns quaternion representing the same rotation, using the opposite rotation direction and opposite angle
 
void normalize ()
 scales this quaternion to make its norm unit
 
Quaternion normalized () const
 
constexpr Quaternion conjugate () const noexcept
 computes conjugate quaternion, which for unit quaternions encodes the opposite rotation
 
constexpr Quaternion inverse () const noexcept
 computes reciprocal quaternion
 
constexpr Vector3< T > operator() (const Vector3< T > &p) const noexcept
 
 operator Matrix3< T > () const
 converts this into 3x3 rotation matrix
 
Quaternionoperator*= (T s)
 
Quaternionoperator/= (T s)
 

Static Public Member Functions

static Quaternion lerp (const Quaternion &q0, const Quaternion &q1, T t)
 given t in [0,1], interpolates linearly two quaternions giving in general not-unit quaternion
 
static Quaternion slerp (Quaternion q0, Quaternion q1, T t)
 given t in [0,1] and two unit quaternions, interpolates them spherically and produces another unit quaternion
 
static Matrix3< T > slerp (const Matrix3< T > &m0, const Matrix3< T > &m1, T t)
 given t in [0,1] and two rotation matrices, interpolates them spherically and produces another rotation matrix
 
static AffineXf3< T > slerp (const AffineXf3< T > &xf0, const AffineXf3< T > &xf1, T t, const Vector3< T > &p={})
 

Public Attributes

a = 1
 real part of the quaternion
 
b = 0
 
c = 0
 
d = 0
 imaginary part: b*i + c*j + d*k
 

Related Symbols

(Note that these are not member symbols.)

template<typename T >
dot (const Quaternion< T > &a, const Quaternion< T > &b)
 dot product
 
template<typename T >
Quaternion< T > operator* (const Quaternion< T > &q1, const Quaternion< T > &q2)
 Hamilton product.
 
template<typename T >
Quaternion< T > getClosestCanonicalQuaternion (const Quaternion< T > &base) noexcept
 returns closest to base canonical quaternion
 
template<typename T >
Matrix3< T > slerp (const Matrix3< T > &m0, const Matrix3< T > &m1, T t)
 given t in [0,1] and two rotation matrices, interpolates them spherically and produces another rotation matrix
 
template<typename T >
AffineXf3< T > slerp (const AffineXf3< T > &xf0, const AffineXf3< T > &xf1, T t, const Vector3< T > &p={})
 
template<typename T >
Matrix3< T > orthonormalized (const Matrix3< T > &m)
 given any matrix, returns a close rotation matrix
 
template<typename T >
AffineXf3< T > orthonormalized (const AffineXf3< T > &xf, const Vector3< T > &center={})
 

Detailed Description

template<typename T>
struct MR::Quaternion< T >

Represents a quaternion following the notations from https://en.wikipedia.org/wiki/Quaternion

Constructor & Destructor Documentation

◆ Quaternion() [1/6]

template<typename T >
MR::Quaternion< T >::Quaternion ( )
constexprdefaultnoexcept

◆ Quaternion() [2/6]

template<typename T >
MR::Quaternion< T >::Quaternion ( T a,
T b,
T c,
T d )
inlineconstexprnoexcept

◆ Quaternion() [3/6]

template<typename T >
MR::Quaternion< T >::Quaternion ( const Vector3< T > & axis,
T angle )
constexprnoexcept

◆ Quaternion() [4/6]

template<typename T >
MR::Quaternion< T >::Quaternion ( T real,
const Vector3< T > & im )
inlineconstexprnoexcept

◆ Quaternion() [5/6]

template<typename T >
MR::Quaternion< T >::Quaternion ( const Matrix3< T > & m)
constexpr

◆ Quaternion() [6/6]

template<typename T >
MR::Quaternion< T >::Quaternion ( const Vector3< T > & from,
const Vector3< T > & to )
constexprnoexcept

finds shorter arc rotation quaternion from one vector to another

Member Function Documentation

◆ angle()

template<typename T >
T MR::Quaternion< T >::angle ( ) const
inlinenodiscardconstexprnoexcept

returns angle of rotation encoded in this quaternion

◆ axis()

template<typename T >
Vector3< T > MR::Quaternion< T >::axis ( ) const
inlinenodiscardconstexprnoexcept

returns axis of rotation encoded in this quaternion

◆ conjugate()

template<typename T >
Quaternion MR::Quaternion< T >::conjugate ( ) const
inlinenodiscardconstexprnoexcept

computes conjugate quaternion, which for unit quaternions encodes the opposite rotation

◆ im()

template<typename T >
Vector3< T > MR::Quaternion< T >::im ( ) const
inlinenodiscardconstexprnoexcept

returns imaginary part of the quaternion as a vector

◆ inverse()

template<typename T >
Quaternion MR::Quaternion< T >::inverse ( ) const
inlinenodiscardconstexprnoexcept

computes reciprocal quaternion

◆ lerp()

template<typename T >
static Quaternion MR::Quaternion< T >::lerp ( const Quaternion< T > & q0,
const Quaternion< T > & q1,
T t )
inlinestaticnodiscard

given t in [0,1], interpolates linearly two quaternions giving in general not-unit quaternion

◆ norm()

template<typename T >
T MR::Quaternion< T >::norm ( ) const
inlinenodiscardconstexpr

◆ normalize()

template<typename T >
void MR::Quaternion< T >::normalize ( )
inline

scales this quaternion to make its norm unit

◆ normalized()

template<typename T >
Quaternion MR::Quaternion< T >::normalized ( ) const
inlinenodiscard

◆ normSq()

template<typename T >
T MR::Quaternion< T >::normSq ( ) const
inlinenodiscardconstexpr

◆ operator Matrix3< T >()

template<typename T >
MR::Quaternion< T >::operator Matrix3< T > ( ) const
nodiscard

converts this into 3x3 rotation matrix

◆ operator()()

template<typename T >
Vector3< T > MR::Quaternion< T >::operator() ( const Vector3< T > & p) const
nodiscardconstexprnoexcept

for unit quaternion returns the rotation of point p, which is faster to compute for single point; for multiple points it is faster to create matrix representation and apply it to the points

◆ operator*=()

template<typename T >
Quaternion & MR::Quaternion< T >::operator*= ( T s)
inline

◆ operator-()

template<typename T >
Quaternion MR::Quaternion< T >::operator- ( ) const
inlinenodiscardconstexpr

returns quaternion representing the same rotation, using the opposite rotation direction and opposite angle

◆ operator/=()

template<typename T >
Quaternion & MR::Quaternion< T >::operator/= ( T s)
inline

◆ slerp() [1/3]

template<typename T >
static AffineXf3< T > MR::Quaternion< T >::slerp ( const AffineXf3< T > & xf0,
const AffineXf3< T > & xf1,
T t,
const Vector3< T > & p = {} )
inlinestaticnodiscard

given t in [0,1] and rigid transformations, interpolates them spherically and produces another rigid transformation; p is the only point that will have straight line movement during interpolation

◆ slerp() [2/3]

template<typename T >
static Matrix3< T > MR::Quaternion< T >::slerp ( const Matrix3< T > & m0,
const Matrix3< T > & m1,
T t )
inlinestaticnodiscard

given t in [0,1] and two rotation matrices, interpolates them spherically and produces another rotation matrix

◆ slerp() [3/3]

template<typename T >
static Quaternion MR::Quaternion< T >::slerp ( Quaternion< T > q0,
Quaternion< T > q1,
T t )
staticnodiscard

given t in [0,1] and two unit quaternions, interpolates them spherically and produces another unit quaternion

Friends And Related Symbol Documentation

◆ dot()

template<typename T >
T dot ( const Quaternion< T > & a,
const Quaternion< T > & b )
related

dot product

◆ getClosestCanonicalQuaternion()

template<typename T >
Quaternion< T > getClosestCanonicalQuaternion ( const Quaternion< T > & base)
related

returns closest to base canonical quaternion

◆ operator*()

template<typename T >
Quaternion< T > operator* ( const Quaternion< T > & q1,
const Quaternion< T > & q2 )
related

Hamilton product.

◆ orthonormalized() [1/2]

template<typename T >
AffineXf3< T > orthonormalized ( const AffineXf3< T > & xf,
const Vector3< T > & center = {} )
related

given any affine transformation, returns a close rigid transformation; center point will be transformed to same point by both input and output transformations

◆ orthonormalized() [2/2]

template<typename T >
Matrix3< T > orthonormalized ( const Matrix3< T > & m)
related

given any matrix, returns a close rotation matrix

◆ slerp() [1/2]

template<typename T >
AffineXf3< T > slerp ( const AffineXf3< T > & xf0,
const AffineXf3< T > & xf1,
T t,
const Vector3< T > & p = {} )
related

given t in [0,1] and rigid transformations, interpolates them spherically and produces another rigid transformation; p is the only point that will have straight line movement during interpolation

◆ slerp() [2/2]

template<typename T >
Matrix3< T > slerp ( const Matrix3< T > & m0,
const Matrix3< T > & m1,
T t )
related

given t in [0,1] and two rotation matrices, interpolates them spherically and produces another rotation matrix

Member Data Documentation

◆ a

template<typename T >
T MR::Quaternion< T >::a = 1

real part of the quaternion

◆ b

template<typename T >
T MR::Quaternion< T >::b = 0

◆ c

template<typename T >
T MR::Quaternion< T >::c = 0

◆ d

template<typename T >
T MR::Quaternion< T >::d = 0

imaginary part: b*i + c*j + d*k


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