Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
sf::TQuaternion< T > Class Template Reference

Generic type Quaternion. More...

#include <TQuaternion.h>

Collaboration diagram for sf::TQuaternion< T >:

Classes

union  data_type
 Storage union of the 3D coordinate making the x,y,z,w accessible as an array. More...
 

Public Types

enum  EElement : size_t { realW = 0 , imagX = 1 , imagY = 2 , imagZ = 3 }
 Enumerate for identifying a matrix axis. More...
 
typedef T value_type
 Type declaration of the coordinate storage values.
 

Public Member Functions

 TQuaternion ()=default
 Default Constructor.
 
 TQuaternion (const TQuaternion &)
 Copy Constructor.
 
 TQuaternion (T real, const TVector3D< T > &imag)
 Initializing constructor is used in operators and sets the member variables directly.
 
 TQuaternion (const TVector3D< T > &axis, T angle)
 Constructor for creating rotations by specifying the angle of rotation and the axis around which to rotate, this axis does not have to be normalized.
 
 TQuaternion (T real_w, T imag_x, T imag_y, T imag_z)
 Initializing constructor for 4 element parts.
 
TQuaternionassign (T real_w, T imag_x, T imag_y, T imag_z)
 Assigns of another instance elements.
 
TQuaternionassign (const TQuaternion &)
 Assigns of another instance elements.
 
TQuaternionoperator= (const TQuaternion &)
 Assignment operator.
 
T & operator[] (size_t)
 Array access operator.
 
const T & operator[] (size_t) const
 Array access const operator to the elements.
 
real () const
 Gets the real part of this instance.
 
T & real ()
 Gets the real part reference of this instance.
 
TVector3D< T > imaginary () const
 Get the imaginary part as a 3D-vector.
 
w () const
 Gets the w or real part of this instance. Same as real() method.
 
T & w ()
 Gets the w or real part reference of this instance. Same as real() method.
 
x () const
 Get the imaginary X-part of this instance.
 
T & x ()
 Get the imaginary X-part reference of this instance.
 
y () const
 Get the imaginary Y-part of this instance.
 
T & y ()
 Get the imaginary Y-part reference of this instance.
 
z () const
 Get the imaginary Z-part of this instance.
 
T & z ()
 Get the imaginary Z-part reference of this instance.
 
TQuaternion conjugate () const
 Gets a copy of this instance where the imaginary (vector) part of a quaternion is negated. The conjugate of a quaternion is a simple operation that reflects the imaginary components of the quaternion while leaving the real component unchanged. It is often used in quaternion operations such as finding the inverse or performing transformations.
 
TQuaternion inverse () const
 Gets the inverse of the current instance. The inverse of a quaternion is a quaternion that "reverses" the effect of the original quaternion when combined through quaternion multiplication. For unit quaternions, the inverse undoes the rotation described by the quaternion. This property is analogous to the inverse of a matrix or a number.
 
TQuaternioninvert ()
 Turns this instance into it inverse.
 
TQuaternionnormalize ()
 Normalizes this instance.
 
TQuaternion normalized () const
 Get a normalizes copy of this instance.
 
magnitudeSqr () const
 Gets the squared magnitude which is used in computations and the magnitude() method for the actual magnitude.
 
magnitude () const
 Gets the magnitude of this quaternion. The magnitude (or norm) of a quaternion q=a+bi+cj+dk, where a, b, c, and d are real numbers, is calculated similarly to the magnitude of a 4-dimensional vector. All element values squared and added together.
 
TMatrix44< T > toMatrix (TMatrix44< T > &) const
 Sets the orientation part of the passed TMatrix instance.
 
TMatrix44< T > toMatrix () const
 Get the matrix having only the orientation part set using this instance normalized version. Before the matrix is calculated the quaternion is normalized.
 
TQuaternionfromMatrix (const T[4][4])
 Transforms a rotation matrix to this Quaternion. Throws an exception when the passed matrix is not a rotation matrix.
 
TVector3D< T > transform (TVector3D< T > v) const
 Transforms a 3D-vector not using the quaternion directly instead of a matrix.
 
TQuaternion operator- () const
 Negation operator.
 
TQuaternionoperator+= (const TQuaternion &)
 Addition assignment operator.
 
TQuaternionoperator-= (const TQuaternion &)
 Subtraction assignment operator.
 
TQuaternionoperator*= (const TQuaternion &)
 Multiplication assignment operator.
 
TQuaternionoperator/= (const TQuaternion &)
 Division assignment operator.
 
TQuaternionoperator^= (const TQuaternion &)
 operator.
 
TQuaternionoperator*= (T c)
 Multiplication assignment operator.
 
TQuaternionoperator/= (T c)
 Division operator.
 
TQuaternion operator* (T) const
 Pointer cast operator.
 
TQuaternion operator/ (T) const
 operator.
 
bool isEqual (const TQuaternion &quat, T tol=tolerance) const
 Compares the passed quaternion within the set tolerance.
 
bool operator== (const TQuaternion &) const
 operator.
 
bool operator!= (const TQuaternion &) const
 operator.
 
TQuaternion squared () const
 Squares this instance. If the quaternion is a unit quaternion (meaning it has magnitude 1), squaring it produces another quaternion with the same magnitude. When a unit quaternion represents a rotation, squaring the quaternion effectively doubles the rotation angle while keeping the axis the same.
 
TQuaternion log () const
 Gets the logarithm form of this instance. The logarithm log(q) of a quaternion is a mathematical operation that maps the quaternion from its rotational form to a form that can be linearly interpolated in logarithmic space. This is particularly useful for spherical blending or spline interpolation of rotations, where transformations are more natural in logarithmic form. To move back from the logarithmic form to a quaternion, use the quaternion exponential exp(), which reconstructs the quaternion from its angle-axis form. By converting a quaternion to its logarithmic form, it allows linearly interpolate between two rotations. This is helpful in spline-based interpolation techniques for smooth rotational blending. Before the logarithm is calculated the quaternion is normalized and result is scaled back accordingly.
 
TQuaternion exp () const
 Gets the exponential of a quaternion which is the inverse of log(). Moves back from the logarithmic form to a quaternion, which reconstructs the quaternion from its angle-axis form.
 
TQuaternion interpolate (const TQuaternion &q, T t) const
 Spherical Linear Interpolation (SLERP) function. Used to smoothly blending or transitioning between two quaternions, typically representing rotations in 3D space. Interpolation is used in animation that require smooth rotational transitions, as it avoids issues like gimbal lock and provides a smooth, natural path between orientations.
 
TQuaternion interpolateLogarithmic (const TQuaternion &q, T t) const
 Implements a logarithmic interpolation function.
 
std::string toString () const
 Gets the string representation of the quaternion formed like '(x,y,z,r)'.
 
TQuaternionfromString (const std::string &s) noexcept(false)
 Gets the quaternion values from the string representation formed like '(1,2,3,4)'. Throws an exception when the string is not in the correct format.
 

Static Public Attributes

static constexpr auto tolerance = TVector3D<T>::tolerance
 Tolerance for when comparing in the equal operator.
 

Protected Attributes

union sf::TQuaternion::data_type _data
 

Detailed Description

template<typename T>
class sf::TQuaternion< T >

Generic type Quaternion.

Member Typedef Documentation

◆ value_type

template<typename T >
typedef T sf::TQuaternion< T >::value_type

Type declaration of the coordinate storage values.

Member Enumeration Documentation

◆ EElement

template<typename T >
enum sf::TQuaternion::EElement : size_t

Enumerate for identifying a matrix axis.

Enumerator
realW 

Translation axis of the matrix.

imagX 

X imaginary part of the quaternion.

imagY 

Y imaginary part of the quaternion.

imagZ 

Z imaginary part of the quaternion.

Constructor & Destructor Documentation

◆ TQuaternion() [1/5]

template<typename T >
sf::TQuaternion< T >::TQuaternion ( )
default

Default Constructor.

◆ TQuaternion() [2/5]

template<typename T >
sf::TQuaternion< T >::TQuaternion ( const TQuaternion< T > &  )

Copy Constructor.

◆ TQuaternion() [3/5]

template<typename T >
sf::TQuaternion< T >::TQuaternion ( real,
const TVector3D< T > &  imag 
)

Initializing constructor is used in operators and sets the member variables directly.

◆ TQuaternion() [4/5]

template<typename T >
sf::TQuaternion< T >::TQuaternion ( const TVector3D< T > &  axis,
angle 
)

Constructor for creating rotations by specifying the angle of rotation and the axis around which to rotate, this axis does not have to be normalized.

◆ TQuaternion() [5/5]

template<typename T >
sf::TQuaternion< T >::TQuaternion ( real_w,
imag_x,
imag_y,
imag_z 
)

Initializing constructor for 4 element parts.

Member Function Documentation

◆ assign() [1/2]

template<typename T >
TQuaternion & sf::TQuaternion< T >::assign ( const TQuaternion< T > &  )

Assigns of another instance elements.

◆ assign() [2/2]

template<typename T >
TQuaternion & sf::TQuaternion< T >::assign ( real_w,
imag_x,
imag_y,
imag_z 
)

Assigns of another instance elements.

◆ conjugate()

template<typename T >
TQuaternion sf::TQuaternion< T >::conjugate ( ) const

Gets a copy of this instance where the imaginary (vector) part of a quaternion is negated. The conjugate of a quaternion is a simple operation that reflects the imaginary components of the quaternion while leaving the real component unchanged. It is often used in quaternion operations such as finding the inverse or performing transformations.

◆ exp()

template<typename T >
TQuaternion sf::TQuaternion< T >::exp ( ) const

Gets the exponential of a quaternion which is the inverse of log(). Moves back from the logarithmic form to a quaternion, which reconstructs the quaternion from its angle-axis form.

Returns
Regular quaternion.

◆ fromMatrix()

template<typename T >
TQuaternion & sf::TQuaternion< T >::fromMatrix ( const T  [4][4])

Transforms a rotation matrix to this Quaternion. Throws an exception when the passed matrix is not a rotation matrix.

Exceptions
std::invalid_argument

◆ fromString()

template<typename T >
TQuaternion & sf::TQuaternion< T >::fromString ( const std::string &  s)

Gets the quaternion values from the string representation formed like '(1,2,3,4)'. Throws an exception when the string is not in the correct format.

Exceptions
std::invalid_argument

◆ imaginary()

template<typename T >
TVector3D< T > sf::TQuaternion< T >::imaginary ( ) const

Get the imaginary part as a 3D-vector.

◆ interpolate()

template<typename T >
TQuaternion sf::TQuaternion< T >::interpolate ( const TQuaternion< T > &  q,
t 
) const

Spherical Linear Interpolation (SLERP) function. Used to smoothly blending or transitioning between two quaternions, typically representing rotations in 3D space. Interpolation is used in animation that require smooth rotational transitions, as it avoids issues like gimbal lock and provides a smooth, natural path between orientations.

Parameters
qQuaternion to transition to.
tTransition ranges from 0 to 1.
Returns
Intermediate quaternion.

◆ interpolateLogarithmic()

template<typename T >
TQuaternion sf::TQuaternion< T >::interpolateLogarithmic ( const TQuaternion< T > &  q,
t 
) const

Implements a logarithmic interpolation function.

Parameters
qTargeted quaternion value.
tValue from 0.0 to 1.0
Returns

◆ inverse()

template<typename T >
TQuaternion sf::TQuaternion< T >::inverse ( ) const

Gets the inverse of the current instance. The inverse of a quaternion is a quaternion that "reverses" the effect of the original quaternion when combined through quaternion multiplication. For unit quaternions, the inverse undoes the rotation described by the quaternion. This property is analogous to the inverse of a matrix or a number.

◆ invert()

template<typename T >
TQuaternion & sf::TQuaternion< T >::invert ( )

Turns this instance into it inverse.

See also
inverse()

◆ isEqual()

template<typename T >
bool sf::TQuaternion< T >::isEqual ( const TQuaternion< T > &  quat,
tol = tolerance 
) const

Compares the passed quaternion within the set tolerance.

Parameters
quatVector to compare with.
tolThe tolerance when comparing which has a default.
Returns
True when equal.

◆ log()

template<typename T >
TQuaternion sf::TQuaternion< T >::log ( ) const

Gets the logarithm form of this instance. The logarithm log(q) of a quaternion is a mathematical operation that maps the quaternion from its rotational form to a form that can be linearly interpolated in logarithmic space. This is particularly useful for spherical blending or spline interpolation of rotations, where transformations are more natural in logarithmic form. To move back from the logarithmic form to a quaternion, use the quaternion exponential exp(), which reconstructs the quaternion from its angle-axis form. By converting a quaternion to its logarithmic form, it allows linearly interpolate between two rotations. This is helpful in spline-based interpolation techniques for smooth rotational blending. Before the logarithm is calculated the quaternion is normalized and result is scaled back accordingly.

Returns
Logarithm quaternion.

◆ magnitude()

template<typename T >
T sf::TQuaternion< T >::magnitude ( ) const

Gets the magnitude of this quaternion. The magnitude (or norm) of a quaternion q=a+bi+cj+dk, where a, b, c, and d are real numbers, is calculated similarly to the magnitude of a 4-dimensional vector. All element values squared and added together.

◆ magnitudeSqr()

template<typename T >
T sf::TQuaternion< T >::magnitudeSqr ( ) const

Gets the squared magnitude which is used in computations and the magnitude() method for the actual magnitude.

Returns
Square root of the magnitude.

◆ normalize()

template<typename T >
TQuaternion & sf::TQuaternion< T >::normalize ( )

Normalizes this instance.

◆ normalized()

template<typename T >
TQuaternion sf::TQuaternion< T >::normalized ( ) const

Get a normalizes copy of this instance.

◆ operator!=()

template<typename T >
bool sf::TQuaternion< T >::operator!= ( const TQuaternion< T > &  ) const

operator.

◆ operator*()

template<typename T >
TQuaternion sf::TQuaternion< T >::operator* ( ) const

Pointer cast operator.

◆ operator*=() [1/2]

template<typename T >
TQuaternion & sf::TQuaternion< T >::operator*= ( const TQuaternion< T > &  )

Multiplication assignment operator.

◆ operator*=() [2/2]

template<typename T >
TQuaternion & sf::TQuaternion< T >::operator*= ( c)

Multiplication assignment operator.

◆ operator+=()

template<typename T >
TQuaternion & sf::TQuaternion< T >::operator+= ( const TQuaternion< T > &  )

Addition assignment operator.

◆ operator-()

template<typename T >
TQuaternion sf::TQuaternion< T >::operator- ( ) const

Negation operator.

◆ operator-=()

template<typename T >
TQuaternion & sf::TQuaternion< T >::operator-= ( const TQuaternion< T > &  )

Subtraction assignment operator.

◆ operator/()

template<typename T >
TQuaternion sf::TQuaternion< T >::operator/ ( ) const

operator.

◆ operator/=() [1/2]

template<typename T >
TQuaternion & sf::TQuaternion< T >::operator/= ( const TQuaternion< T > &  )

Division assignment operator.

◆ operator/=() [2/2]

template<typename T >
TQuaternion & sf::TQuaternion< T >::operator/= ( c)

Division operator.

◆ operator=()

template<typename T >
TQuaternion & sf::TQuaternion< T >::operator= ( const TQuaternion< T > &  )

Assignment operator.

◆ operator==()

template<typename T >
bool sf::TQuaternion< T >::operator== ( const TQuaternion< T > &  ) const

operator.

◆ operator[]() [1/2]

template<typename T >
T & sf::TQuaternion< T >::operator[] ( size_t  )

Array access operator.

Exceptions
std::out_of_range

◆ operator[]() [2/2]

template<typename T >
const T & sf::TQuaternion< T >::operator[] ( size_t  ) const

Array access const operator to the elements.

Exceptions
std::out_of_range

◆ operator^=()

template<typename T >
TQuaternion & sf::TQuaternion< T >::operator^= ( const TQuaternion< T > &  )

operator.

◆ real() [1/2]

template<typename T >
T & sf::TQuaternion< T >::real ( )

Gets the real part reference of this instance.

◆ real() [2/2]

template<typename T >
T sf::TQuaternion< T >::real ( ) const

Gets the real part of this instance.

◆ squared()

template<typename T >
TQuaternion sf::TQuaternion< T >::squared ( ) const

Squares this instance. If the quaternion is a unit quaternion (meaning it has magnitude 1), squaring it produces another quaternion with the same magnitude. When a unit quaternion represents a rotation, squaring the quaternion effectively doubles the rotation angle while keeping the axis the same.

Returns
Squared quaternion.

◆ toMatrix() [1/2]

template<typename T >
TMatrix44< T > sf::TQuaternion< T >::toMatrix ( ) const

Get the matrix having only the orientation part set using this instance normalized version. Before the matrix is calculated the quaternion is normalized.

◆ toMatrix() [2/2]

template<typename T >
TMatrix44< T > sf::TQuaternion< T >::toMatrix ( TMatrix44< T > &  ) const

Sets the orientation part of the passed TMatrix instance.

◆ toString()

template<typename T >
std::string sf::TQuaternion< T >::toString ( ) const

Gets the string representation of the quaternion formed like '(x,y,z,r)'.

◆ transform()

template<typename T >
TVector3D< T > sf::TQuaternion< T >::transform ( TVector3D< T >  v) const

Transforms a 3D-vector not using the quaternion directly instead of a matrix.

◆ w() [1/2]

template<typename T >
T & sf::TQuaternion< T >::w ( )

Gets the w or real part reference of this instance. Same as real() method.

◆ w() [2/2]

template<typename T >
T sf::TQuaternion< T >::w ( ) const

Gets the w or real part of this instance. Same as real() method.

◆ x() [1/2]

template<typename T >
T & sf::TQuaternion< T >::x ( )

Get the imaginary X-part reference of this instance.

◆ x() [2/2]

template<typename T >
T sf::TQuaternion< T >::x ( ) const

Get the imaginary X-part of this instance.

◆ y() [1/2]

template<typename T >
T & sf::TQuaternion< T >::y ( )

Get the imaginary Y-part reference of this instance.

◆ y() [2/2]

template<typename T >
T sf::TQuaternion< T >::y ( ) const

Get the imaginary Y-part of this instance.

◆ z() [1/2]

template<typename T >
T & sf::TQuaternion< T >::z ( )

Get the imaginary Z-part reference of this instance.

◆ z() [2/2]

template<typename T >
T sf::TQuaternion< T >::z ( ) const

Get the imaginary Z-part of this instance.

Member Data Documentation

◆ _data

template<typename T >
union sf::TQuaternion::data_type sf::TQuaternion< T >::_data
protected

◆ tolerance

template<typename T >
constexpr auto sf::TQuaternion< T >::tolerance = TVector3D<T>::tolerance
staticconstexpr

Tolerance for when comparing in the equal operator.

Used as: std::fabs(x1 - x2) < tolerance


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