UFO 1.0.0
An Efficient Probabilistic 3D Mapping Framework That Embraces the Unknown
Loading...
Searching...
No Matches
ufo::Quat< T > Struct Template Reference

Unit quaternion representing an orientation or rotation in 3-D space. More...

#include <lib/numeric/include/ufo/numeric/quat.hpp>

Public Types

using size_type = std::size_t
 
using value_type = T
 

Public Member Functions

constexpr Quat () noexcept=default
 Default constructor; initializes to the identity rotation (1, 0, 0, 0).
 
constexpr Quat (Mat< 3, 3, T > const &m) noexcept
 Constructs a quaternion from a row-major 3×3 rotation matrix.
 
constexpr Quat (Mat< 4, 4, T > const &m) noexcept
 Constructs a quaternion from the upper-left 3×3 block of a 4×4 matrix.
 
constexpr Quat (Quat const &) noexcept=default
 Copy constructor.
 
constexpr Quat (T w, T x, T y, T z) noexcept
 Constructs a quaternion from explicit (w, x, y, z) components.
 
 Quat (Vec< 3, T > const &euler_angles)
 Constructs a quaternion from Euler angles (pitch, yaw, roll) in radians.
 
 Quat (Vec< 3, T > const &u, Vec< 3, T > const &v)
 Constructs the shortest-arc rotation quaternion from u to v.
 
template<std::floating_point U>
constexpr explicit (!std::is_same_v< T, U >) Quat(Quat< U > const &q) noexcept
 Converting constructor from a quaternion with a different scalar type.
 
constexpr operator Mat< 3, 3, T > () const noexcept
 Converts to a row-major 3×3 rotation matrix.
 
constexpr operator Mat< 4, 4, T > () const noexcept
 Converts to a row-major 4×4 homogeneous rotation matrix.
 
constexpr Quatoperator*= (Quat const &q) noexcept
 Hamilton (quaternion) product in place.
 
constexpr Quatoperator*= (T s) noexcept
 Scales all components by scalar s.
 
constexpr Quatoperator+= (Quat const &q) noexcept
 Component-wise addition.
 
constexpr Quatoperator-= (Quat const &q) noexcept
 Component-wise subtraction.
 
constexpr Quatoperator/= (T s) noexcept
 Divides all components by scalar s.
 
constexpr Quatoperator= (Quat const &) noexcept=default
 Copy assignment operator.
 
template<std::floating_point U>
constexpr Quatoperator= (Quat< U > const &rhs) noexcept
 Converting assignment from a quaternion with a different scalar type.
 
constexpr bool operator== (Quat const &) const noexcept=default
 Component-wise equality comparison.
 
constexpr auto & operator[] (this auto &self, size_type pos) noexcept
 Component access by index: 0->w, 1->x, 2->y, 3->z.
 
void swap (Quat &other) noexcept
 Swaps all components with other.
 

Static Public Member Functions

static constexpr size_type size () noexcept
 Returns the number of components (always 4: w, x, y, z).
 

Public Attributes

w {1}
 Quaternion components. Must satisfy w^2 + x^2 + y^2 + z^2 == 1 for a valid rotation.
 
x {}
 
y {}
 
z {}
 

Detailed Description

template<std::floating_point T = float>
struct ufo::Quat< T >

Unit quaternion representing an orientation or rotation in 3-D space.

Template Parameters
TFloating-point scalar type (default: float).

Stored as (w, x, y, z) with the convention that the identity quaternion has w = 1 and x = y = z = 0. All rotation operations assume the quaternion is unit-length; use normalize() when in doubt.

Definition at line 76 of file quat.hpp.

Member Typedef Documentation

◆ size_type

template<std::floating_point T = float>
using ufo::Quat< T >::size_type = std::size_t

Definition at line 78 of file quat.hpp.

◆ value_type

template<std::floating_point T = float>
using ufo::Quat< T >::value_type = T

Definition at line 77 of file quat.hpp.

Constructor & Destructor Documentation

◆ Quat() [1/5]

template<std::floating_point T = float>
constexpr ufo::Quat< T >::Quat ( w,
x,
y,
z 
)
inlineconstexprnoexcept

Constructs a quaternion from explicit (w, x, y, z) components.

Parameters
[in]wReal part.
[in]xFirst imaginary component.
[in]ySecond imaginary component.
[in]zThird imaginary component.

Definition at line 127 of file quat.hpp.

◆ Quat() [2/5]

template<std::floating_point T = float>
ufo::Quat< T >::Quat ( Vec< 3, T > const &  u,
Vec< 3, T > const &  v 
)
inline

Constructs the shortest-arc rotation quaternion from u to v.

Parameters
[in]uSource direction vector (need not be normalised).
[in]vTarget direction vector (need not be normalised).

If u and v are antiparallel the rotation axis is chosen arbitrarily (perpendicular to u) to produce a well-defined 180° rotation.

Definition at line 136 of file quat.hpp.

◆ Quat() [3/5]

template<std::floating_point T = float>
ufo::Quat< T >::Quat ( Vec< 3, T > const &  euler_angles)
inlineexplicit

Constructs a quaternion from Euler angles (pitch, yaw, roll) in radians.

Parameters
[in]euler_anglesVec<3, T> with components (pitch, yaw, roll) — matches the ROS 2 setRPY convention.

Definition at line 158 of file quat.hpp.

◆ Quat() [4/5]

template<std::floating_point T = float>
constexpr ufo::Quat< T >::Quat ( Mat< 3, 3, T > const &  m)
inlineconstexprnoexcept

Constructs a quaternion from a row-major 3×3 rotation matrix.

Parameters
[in]mRow-major rotation matrix where m[row][col] = R_{row,col}.

Uses Shepperd's method to select the numerically best branch.

Definition at line 178 of file quat.hpp.

◆ Quat() [5/5]

template<std::floating_point T = float>
constexpr ufo::Quat< T >::Quat ( Mat< 4, 4, T > const &  m)
inlineconstexprnoexcept

Constructs a quaternion from the upper-left 3×3 block of a 4×4 matrix.

Parameters
[in]mRow-major 4×4 homogeneous matrix; only the rotation submatrix is used.

Definition at line 214 of file quat.hpp.

Member Function Documentation

◆ explicit()

template<std::floating_point T = float>
template<std::floating_point U>
constexpr ufo::Quat< T >::explicit ( !std::is_same_v< T, U >  ) const &
inlineconstexprnoexcept

Converting constructor from a quaternion with a different scalar type.

Template Parameters
USource scalar type.
Parameters
[in]qSource quaternion; each component is static_cast to T.

Implicit when U == T; explicit otherwise.

Definition at line 112 of file quat.hpp.

◆ operator Mat< 4, 4, T >()

template<std::floating_point T = float>
constexpr ufo::Quat< T >::operator Mat< 4, 4, T > ( ) const
inlineexplicitconstexprnoexcept

Converts to a row-major 4×4 homogeneous rotation matrix.

Returns
Mat<4, 4, T> with the 3×3 rotation block in the upper-left corner, identity in the last row and column, and 0 in the last column rows 0–2.

Definition at line 272 of file quat.hpp.

◆ operator*=() [1/2]

template<std::floating_point T = float>
constexpr Quat & ufo::Quat< T >::operator*= ( Quat< T > const &  q)
inlineconstexprnoexcept

Hamilton (quaternion) product in place.

Parameters
[in]qRight-hand side quaternion.
Returns
Reference to *this.

Definition at line 342 of file quat.hpp.

◆ operator*=() [2/2]

template<std::floating_point T = float>
constexpr Quat & ufo::Quat< T >::operator*= ( s)
inlineconstexprnoexcept

Scales all components by scalar s.

Parameters
[in]sScalar multiplier.
Returns
Reference to *this.

Definition at line 357 of file quat.hpp.

◆ operator-=()

template<std::floating_point T = float>
constexpr Quat & ufo::Quat< T >::operator-= ( Quat< T > const &  q)
inlineconstexprnoexcept

Component-wise subtraction.

Parameters
[in]qQuaternion to subtract.
Returns
Reference to *this.

Definition at line 328 of file quat.hpp.

◆ operator/=()

template<std::floating_point T = float>
constexpr Quat & ufo::Quat< T >::operator/= ( s)
inlineconstexprnoexcept

Divides all components by scalar s.

Parameters
[in]sScalar divisor.
Returns
Reference to *this.

Definition at line 371 of file quat.hpp.

◆ operator=()

template<std::floating_point T = float>
template<std::floating_point U>
constexpr Quat & ufo::Quat< T >::operator= ( Quat< U > const &  rhs)
inlineconstexprnoexcept

Converting assignment from a quaternion with a different scalar type.

Template Parameters
USource scalar type.
Parameters
[in]rhsSource quaternion; each component is static_cast to T.
Returns
Reference to *this.

Definition at line 235 of file quat.hpp.

◆ operator==()

template<std::floating_point T = float>
constexpr bool ufo::Quat< T >::operator== ( Quat< T > const &  ) const
constexprdefaultnoexcept

Component-wise equality comparison.

Parameters
[in]otherQuaternion to compare with.
Returns
true if all components are equal, false otherwise.

Does not consider two quaternions representing the same rotation (e.g. q and -q) as equal; use dot(q1, q2) to check for that instead.

Member Data Documentation

◆ w

template<std::floating_point T = float>
T ufo::Quat< T >::w {1}

Quaternion components. Must satisfy w^2 + x^2 + y^2 + z^2 == 1 for a valid rotation.

Definition at line 84 of file quat.hpp.

◆ x

template<std::floating_point T = float>
T ufo::Quat< T >::x {}

Definition at line 85 of file quat.hpp.

◆ y

template<std::floating_point T = float>
T ufo::Quat< T >::y {}

Definition at line 86 of file quat.hpp.

◆ z

template<std::floating_point T = float>
T ufo::Quat< T >::z {}

Definition at line 87 of file quat.hpp.


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