Blender V5.3
blender::math::QuaternionBase< T > Struct Template Reference

#include <BLI_math_quaternion_types.hh>

Public Member Functions

 QuaternionBase ()=default
 QuaternionBase (const T &new_w, const T &new_x, const T &new_y, const T &new_z)
 QuaternionBase (const VecBase< T, 4 > &vec)
 QuaternionBase (const T &real, const VecBase< T, 3 > &imaginary)
 operator VecBase< T, 4 > () const
 operator const T * () const
 operator T* ()
const VecBase< T, 3 > & imaginary_part () const
VecBase< T, 3 > & imaginary_part ()
QuaternionBase & operator*= (const QuaternionBase &b) &
constexpr uint64_t hash () const
void hash_unique (UniqueHashBytes &hash) const
Quaternion
AngleRadianBase< T > twist_angle (const Axis axis) const
QuaternionBase twist (const Axis axis) const
QuaternionBase swing (const Axis axis) const
QuaternionBase wrapped_around (const QuaternionBase &reference) const

Static Public Member Functions

static QuaternionBase identity ()
static QuaternionBase zero ()

Public Attributes

T w
T x
T y
T z

Friends

QuaternionBase operator* (const QuaternionBase &a, const QuaternionBase &b)
QuaternionBase operator* (const QuaternionBase &a, const T &b)
QuaternionBase operator- (const QuaternionBase &a)
bool operator== (const QuaternionBase &a, const QuaternionBase &b)=default
std::ostream & operator<< (std::ostream &stream, const QuaternionBase &rot)

Conversion from/to Expmap

VecBase< T, 3 > expmap () const
static QuaternionBase expmap (const VecBase< T, 3 > &expmap)

Detailed Description

template<typename T>
struct blender::math::QuaternionBase< T >

A math::QuaternionBase<T> represents either an orientation or a rotation.

Mainly used for rigging and armature deformations as they have nice mathematical properties (eg: smooth shortest path interpolation). A math::QuaternionBase<T> is cheaper to combine than MatBase<T, 3, 3>. However, transforming points is slower. Consider converting to a rotation matrix if you are rotating many points.

See this for more information: https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation#Performance_comparisons

Definition at line 36 of file BLI_math_quaternion_types.hh.

Constructor & Destructor Documentation

◆ QuaternionBase() [1/4]

◆ QuaternionBase() [2/4]

template<typename T>
blender::math::QuaternionBase< T >::QuaternionBase ( const T & new_w,
const T & new_x,
const T & new_y,
const T & new_z )
inline

Definition at line 41 of file BLI_math_quaternion_types.hh.

◆ QuaternionBase() [3/4]

template<typename T>
blender::math::QuaternionBase< T >::QuaternionBase ( const VecBase< T, 4 > & vec)
inlineexplicit

Creates a quaternion from an vector without reordering the components.

Note
Component order must follow the scalar constructor (w, x, y, z).

Definition at line 48 of file BLI_math_quaternion_types.hh.

◆ QuaternionBase() [4/4]

template<typename T>
blender::math::QuaternionBase< T >::QuaternionBase ( const T & real,
const VecBase< T, 3 > & imaginary )
inline

Creates a quaternion from real (w) and imaginary parts (x, y, z).

Definition at line 53 of file BLI_math_quaternion_types.hh.

Member Function Documentation

◆ expmap() [1/2]

template<typename T>
VecBase< T, 3 > blender::math::QuaternionBase< T >::expmap ( ) const

Create an exponential map representation of this quaternion. An exponential map is basically the rotation axis multiplied by the rotation angle.

Definition at line 698 of file BLI_math_quaternion.hh.

References blender::BLI_assert(), blender::math::is_unit_scale(), and blender::math::to_axis_angle().

◆ expmap() [2/2]

template<typename T>
QuaternionBase< T > blender::math::QuaternionBase< T >::expmap ( const VecBase< T, 3 > & expmap)
static

Create a quaternion from an exponential map representation. An exponential map is basically the rotation axis multiplied by the rotation angle.

Definition at line 686 of file BLI_math_quaternion.hh.

References angle(), expmap(), identity(), blender::math::normalize_and_get_length(), QuaternionBase(), T, and blender::math::to_quaternion().

Referenced by expmap(), blender::bke::attribute_math::mix3(), blender::bke::attribute_math::mix4(), and blender::bke::attribute_math::detail::quat_to_expmap().

◆ hash()

template<typename T>
uint64_t blender::math::QuaternionBase< T >::hash ( ) const
inlineconstexpr

Definition at line 174 of file BLI_math_quaternion_types.hh.

◆ hash_unique()

template<typename T>
void blender::math::QuaternionBase< T >::hash_unique ( UniqueHashBytes & hash) const
inline

Definition at line 179 of file BLI_math_quaternion_types.hh.

◆ identity()

◆ imaginary_part() [1/2]

template<typename T>
VecBase< T, 3 > & blender::math::QuaternionBase< T >::imaginary_part ( )
inline

Definition at line 126 of file BLI_math_quaternion_types.hh.

◆ imaginary_part() [2/2]

template<typename T>
const VecBase< T, 3 > & blender::math::QuaternionBase< T >::imaginary_part ( ) const
inline

Returns the imaginary part of this quaternion (x, y, z).

Definition at line 122 of file BLI_math_quaternion_types.hh.

Referenced by blender::io::alembic::TypeTraitConverter< math::Quaternion >::convert(), and blender::math::pow().

◆ operator const T *()

template<typename T>
blender::math::QuaternionBase< T >::operator const T * ( ) const
inline

C-style pointer dereference.

Definition at line 84 of file BLI_math_quaternion_types.hh.

◆ operator T*()

template<typename T>
blender::math::QuaternionBase< T >::operator T* ( )
inline

Definition at line 89 of file BLI_math_quaternion_types.hh.

◆ operator VecBase< T, 4 >()

template<typename T>
blender::math::QuaternionBase< T >::operator VecBase< T, 4 > ( ) const
inlineexplicit

Conversions.

Definition at line 77 of file BLI_math_quaternion_types.hh.

◆ operator*=()

template<typename T>
QuaternionBase & blender::math::QuaternionBase< T >::operator*= ( const QuaternionBase< T > & b) &
inline

Definition at line 154 of file BLI_math_quaternion_types.hh.

◆ swing()

template<typename T>
QuaternionBase< T > blender::math::QuaternionBase< T >::swing ( const Axis axis) const

Returns the swing part of this quaternion for the basis axis direction. The swing is the original quaternion minus the twist around axis. So we have the following identity : q = q.swing(axis) * q.twist(axis)

Definition at line 151 of file BLI_math_quaternion.hh.

References blender::math::abs(), blender::math::Axis::as_int(), blender::BLI_assert(), blender::math::canonicalize(), blender::math::invert_normalized(), QuaternionBase(), swing(), and twist().

Referenced by swing().

◆ twist()

template<typename T>
QuaternionBase< T > blender::math::QuaternionBase< T >::twist ( const Axis axis) const

Returns the twist part of this quaternion for the axis direction. The twist is the isolated rotation in the plane whose axis is normal to.

Definition at line 163 of file BLI_math_quaternion.hh.

References blender::math::Axis::as_int(), blender::math::canonicalize(), blender::math::AngleCartesianBase< T >::cos(), blender::math::AngleCartesianBase< T >::from_point(), QuaternionBase(), blender::math::AngleCartesianBase< T >::sin(), T, and twist().

Referenced by swing(), and twist().

◆ twist_angle()

template<typename T>
AngleRadianBase< T > blender::math::QuaternionBase< T >::twist_angle ( const Axis axis) const

Returns the full twist angle for a given axis direction. The twist is the isolated rotation in the plane whose axis is normal to.

Definition at line 143 of file BLI_math_quaternion.hh.

References blender::math::AngleRadianBase< T >::AngleRadianBase(), blender::math::Axis::as_int(), blender::math::canonicalize(), and T.

◆ wrapped_around()

template<typename T>
QuaternionBase< T > blender::math::QuaternionBase< T >::wrapped_around ( const QuaternionBase< T > & reference) const

Methods. Return this quaternions orientation but wrapped around reference.

This means the interpolation between the returned value and reference will always take the shortest path. The angle between them will not be more than pi.

Note
This quaternion is expected to be a unit quaternion.
Works even if reference is not a unit quaternion.

Definition at line 179 of file BLI_math_quaternion.hh.

References blender::BLI_assert(), blender::math::distance_squared(), blender::math::invert_normalized(), blender::math::is_unit_scale(), len(), blender::math::normalize_and_get_length(), QuaternionBase(), blender::result, and T.

Referenced by blender::math::tests::TEST().

◆ zero()

template<typename T>
QuaternionBase blender::math::QuaternionBase< T >::zero ( )
inlinestatic

This is just for convenience. Does not represent a rotation as it is degenerate.

Definition at line 64 of file BLI_math_quaternion_types.hh.

Referenced by blender::math::DualQuaternionBase< float >::identity().

◆ operator* [1/2]

template<typename T>
QuaternionBase operator* ( const QuaternionBase< T > & a,
const QuaternionBase< T > & b )
friend

Operators.

Definition at line 146 of file BLI_math_quaternion_types.hh.

◆ operator* [2/2]

template<typename T>
QuaternionBase operator* ( const QuaternionBase< T > & a,
const T & b )
friend

Definition at line 161 of file BLI_math_quaternion_types.hh.

◆ operator-

template<typename T>
QuaternionBase operator- ( const QuaternionBase< T > & a)
friend

Definition at line 167 of file BLI_math_quaternion_types.hh.

◆ operator<<

template<typename T>
std::ostream & operator<< ( std::ostream & stream,
const QuaternionBase< T > & rot )
friend

Definition at line 184 of file BLI_math_quaternion_types.hh.

◆ operator==

template<typename T>
bool operator== ( const QuaternionBase< T > & a,
const QuaternionBase< T > & b )
friend

Member Data Documentation

◆ w

template<typename T>
T blender::math::QuaternionBase< T >::w

◆ x

◆ y

◆ z


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