cgv
Loading...
Searching...
No Matches
cgv::math::quaternion< T > Class Template Reference

implements a quaternion. More...

#include <quaternion.h>

Inheritance diagram for cgv::math::quaternion< T >:
cgv::math::fvec< T, 4 >

Public Types

enum  AxisEnum { X_AXIS , Y_AXIS , Z_AXIS }
 enumeration of the three coordinate axes More...
 
typedef fvec< T, 4 > base_type
 base class type
 
typedef T coord_type
 coordinate type
 
typedef fvec< T, 3 > vec_type
 type of 3d axis
 
typedef fmat< T, 3, 3 > mat_type
 type of 3x3 matrix
 
typedef fmat< T, 4, 4 > hmat_type
 type of 4x4 matrix
 
- Public Types inherited from cgv::math::fvec< T, 4 >
enum  
 compile-time constant indicating the dimensionality of the vector More...
 
typedef T value_type
 
typedef T & reference
 
typedef const T & const_reference
 
typedef std::size_t size_type
 
typedef std::ptrdiff_t difference_type
 
typedef T * pointer
 
typedef const T * const_pointer
 
typedef T * iterator
 
typedef const T * const_iterator
 
typedef std::reverse_iterator< iterator > reverse_iterator
 
typedef std::reverse_iterator< const_iterator > const_reverse_iterator
 

Public Member Functions

 quaternion (const quaternion< T > &quat)
 copy constructor
 
template<typename S >
 quaternion (const quaternion< S > &q)
 copy constructor with type conversion
 
quaternion< T > & operator= (const quaternion< T > &quat)
 assignement operator
 
 quaternion (AxisEnum axis, coord_type angle)
 construct quaternion from coordinate axis and rotation angle
 
 quaternion (const vec_type &axis, coord_type angle)
 construct quaternion from axis and rotation angle
 
template<class rot_mat_type >
 quaternion (const rot_mat_type &matrix)
 construct quaternion from 3x3 rotation or rotational part of homogeneous 3x4 / 4x4 matrix
 
 quaternion (coord_type w, coord_type x, coord_type y, coord_type z)
 construct quaternion directly
 
 quaternion (coord_type re, const vec_type &im)
 construct quaternion from real part and vector
 
base_typevec ()
 
const base_typevec () const
 
void set (AxisEnum axis, coord_type angle)
 set quaternion from coordinate axis and rotation angle
 
void set (const vec_type &axis, coord_type angle)
 set quaternion from axis and rotation angle
 
void set (const quaternion< T > &quat)
 setter from quaternion
 
template<class rot_mat_type >
void set (const rot_mat_type &M)
 set quaternion from 3x3 rotation or rotational part of homogeneous 3x4 / 4x4 matrix
 
void set (coord_type re, coord_type ix, coord_type iy, coord_type iz)
 set quaternion directly
 
void set (coord_type re, const vec_type &im)
 set quaternion from real part and vector
 
void put_matrix (mat_type &M) const
 compute equivalent 3x3 rotation matrix
 
mat_type get_matrix () const
 return equivalent 3x3 rotation matrix
 
void put_homogeneous_matrix (hmat_type &M) const
 compute equivalent homogeneous 4x4 rotation matrix
 
hmat_type get_homogeneous_matrix () const
 return equivalent 4x4 rotation matrix
 
void set_normal (const vec_type &n)
 initialize quaternion from normal vector
 
void put_normal (coord_type *n)
 extract normal vector
 
void put_image (const vec_type &preimage, vec_type &image) const
 rotate preimage according to quaternion into image
 
void rotate (vec_type &v) const
 rotate vector according to quaternion
 
vec_type get_rotated (const vec_type &v) const
 return rotated vector
 
void rotate (mat_type &m) const
 Rotate a frame according to quaternion.
 
mat_type get_rotated (const mat_type &M) const
 Rotate source frame s into destination frame d.
 
void put_preimage (const vec_type &image, vec_type &preimage) const
 rotate image according to quaternion into preimage
 
void inverse_rotate (vec_type &image) const
 rotate vector according to the inverse quaternion
 
vec_type apply (const vec_type &v) const
 rotate vector according to quaternion
 
quaternion< T > conj () const
 return the conjugate
 
quaternion< T > negated () const
 return the negated quaternion
 
void negate ()
 negate the quaternion
 
void conjugate ()
 compute conjugate
 
quaternion< T > inverse () const
 return the inverse
 
void invert ()
 compute inverse
 
void affin (const quaternion< T > &p, coord_type t, const quaternion< T > &q)
 compute affin combination with angular interpolation
 
void affin (coord_type s, const quaternion< T > &q)
 compute affin combination with angular interpolation
 
quaternion< T > operator- () const
 negation operator
 
quaternion< T > & operator*= (const quaternion< T > &q)
 field multiplication
 
quaternion< T > operator* (const quaternion< T > &q) const
 field multiplication
 
quaternion< T > & operator*= (const T &s)
 in place multiplication with s
 
quaternion< T > operator* (const T &s) const
 multiplication with scalar s
 
coord_type re () const
 return real part
 
coord_typere ()
 return reference to real part
 
void put_im (vec_type &vector) const
 put imaginary part
 
vec_type im () const
 return this as vector
 
coord_type put_axis (vec_type &v) const
 put rotation axis and return rotation angle
 
quaternion< T > exp () const
 exponential map
 
quaternion< T > log () const
 logarithmic map
 
- Public Member Functions inherited from cgv::math::fvec< T, 4 >
 fvec ()
 create an uninitialized vector
 
 fvec (const T &x)
 create a vector where all N components are initialized to the constant value x
 
int int S2 fvec (const fvec< S1, N - 1 > &other, S2 s)
 
 fvec (const fvec< S, N+1 > &other)
 construct from vector of one dimension higher by dropping the highest dimension
 
 fvec (const std::array< T, N > &a)
 construct from std::array of same size
 
void assign (const std::array< T, N > &a)
 set to the contents of the given std::array with same size
 
int int N lift () const
 
vec< T > to_vec () const
 conversion to vector type
 
T & x ()
 return first component
 
const T & x () const
 return first component
 
T & y ()
 return second component
 
const T & y () const
 return second component
 
T & z ()
 return third component
 
const T & z () const
 return third component
 
T & w ()
 return fourth component
 
const T & w () const
 return fourth component
 
T & operator[] (int i)
 return a reference to the component at specified index i
 
const T & operator[] (int i) const
 return a reference to the component at specified index i
 
T & operator() (int i)
 return a reference to the component at specified index i
 
const T & operator() (int i) const
 return a reference to the component at specified index i
 
T * data ()
 return a pointer to the underlying array serving as component storage
 
const T * data () const
 return a pointer to the underlying array serving as component storage
 
iterator begin ()
 return an iterator to the first component of *this
 
const_iterator begin () const
 return an iterator to the first component of *this
 
iterator end ()
 return an iterator past the last component of *this
 
const_iterator end () const
 return an iterator past the last component of *this
 
reverse_iterator rbegin ()
 return a reverse iterator to the first component of the reversed *this that corresponds to the last component of the non-reversed *this
 
const_reverse_iterator rbegin () const
 return a reverse iterator to the first component of the reversed *this that corresponds to the last component of the non-reversed *this
 
reverse_iterator rend ()
 return a reverse iterator past the last component of the reversed *this that corresponds to the component preceding the first component of the non-reversed *this
 
const_reverse_iterator rend () const
 return a reverse iterator past the last component of the reversed *this that corresponds to the component preceding the first component of the non-reversed *this
 
fvec< T, N > & operator+= (const T &s)
 in place addition of a scalar s
 
fvec< T, N > & operator+= (const fvec< S, N > &v)
 in place vector addition
 
fvec< T, N > & operator-= (const T &s)
 in place subtraction by scalar s
 
fvec< T, N > & operator-= (const fvec< S, N > &v)
 in place vector subtraction
 
fvec< T, N > & operator*= (const T &s)
 in place multiplication with s
 
fvec< T, N > & operator*= (const fvec< S, N > &v)
 in place componentwise vector multiplication
 
fvec< T, N > & operator/= (const T &s)
 in place division by scalar s
 
fvec< T, N > & operator/= (const fvec< S, N > &v)
 in place componentwise vector division
 
fvec< T, N > operator+ (const fvec< S, N > &v) const
 vector addition
 
fvec< T, N > operator+ (const T &s) const
 componentwise addition of scalar
 
fvec< T, N > operator- (const fvec< S, N > &v) const
 vector subtraction
 
fvec< T, N > operator- (const T &s) const
 componentwise subtraction of scalar
 
fvec< T, N > operator- () const
 negate the vector
 
fvec< T, N > operator* (const fvec< S, N > &v) const
 componentwise vector multiplication
 
fvec< T, N > operator* (const T &s) const
 multiplication with scalar s
 
fvec< T, N > operator/ (const fvec< S, N > &v) const
 componentwise vector division
 
fvec< T, N > operator/ (const T &s) const
 divide vector by scalar s
 
bool operator== (const fvec< S, N > &v) const
 test for equality
 
bool operator!= (const fvec< S, N > &v) const
 test for inequality
 
sqr_length () const
 square length of vector
 
length () const
 length of the vector L2-Norm
 
void sign ()
 componentwise sign values
 
void step (const fvec< T, N > &r)
 componentwise sign values
 
void abs ()
 componentwise absolute values
 
void ceil ()
 ceil componentwise
 
void floor ()
 floor componentwise
 
void round ()
 round componentwise
 
normalize ()
 normalize the vector using the L2-Norm and return the length
 
safe_normalize ()
 normalize the vector using the L2-Norm and return the length; if length is zero the vector remains unchanged
 

Additional Inherited Members

- Static Public Member Functions inherited from cgv::math::fvec< T, 4 >
static fvec< T, N > zeroh ()
 constuct a homogeneous zero-vector (yields same result as calling fvec<T, N-1>(0).lift() but is faster)
 
static fvec< T, N > from_vec (const vec< T > &)
 conversion from vector
 
static cgv::type::uint32_type size ()
 return number of components
 
- Protected Attributes inherited from cgv::math::fvec< T, 4 >
v [N]
 

Detailed Description

template<typename T>
class cgv::math::quaternion< T >

implements a quaternion.

Definition at line 20 of file quaternion.h.

Member Typedef Documentation

◆ base_type

template<typename T >
typedef fvec<T,4> cgv::math::quaternion< T >::base_type

base class type

Definition at line 26 of file quaternion.h.

◆ coord_type

template<typename T >
typedef T cgv::math::quaternion< T >::coord_type

coordinate type

Definition at line 28 of file quaternion.h.

◆ hmat_type

template<typename T >
typedef fmat<T, 4, 4> cgv::math::quaternion< T >::hmat_type

type of 4x4 matrix

Definition at line 36 of file quaternion.h.

◆ mat_type

template<typename T >
typedef fmat<T, 3, 3> cgv::math::quaternion< T >::mat_type

type of 3x3 matrix

Definition at line 34 of file quaternion.h.

◆ vec_type

template<typename T >
typedef fvec<T,3> cgv::math::quaternion< T >::vec_type

type of 3d axis

Definition at line 32 of file quaternion.h.

Member Enumeration Documentation

◆ AxisEnum

template<typename T >
enum cgv::math::quaternion::AxisEnum

enumeration of the three coordinate axes

Definition at line 30 of file quaternion.h.

Constructor & Destructor Documentation

◆ quaternion() [1/8]

template<typename T >
cgv::math::quaternion< T >::quaternion ( )
inline

standard constructor initializes to unit quaternion

Definition at line 42 of file quaternion.h.

◆ quaternion() [2/8]

template<typename T >
cgv::math::quaternion< T >::quaternion ( const quaternion< T > &  quat)
inline

copy constructor

Definition at line 44 of file quaternion.h.

◆ quaternion() [3/8]

template<typename T >
template<typename S >
cgv::math::quaternion< T >::quaternion ( const quaternion< S > &  q)
inline

copy constructor with type conversion

Definition at line 47 of file quaternion.h.

◆ quaternion() [4/8]

template<typename T >
cgv::math::quaternion< T >::quaternion ( AxisEnum  axis,
coord_type  angle 
)
inline

construct quaternion from coordinate axis and rotation angle

Definition at line 54 of file quaternion.h.

References cgv::math::quaternion< T >::set().

◆ quaternion() [5/8]

template<typename T >
cgv::math::quaternion< T >::quaternion ( const vec_type axis,
coord_type  angle 
)
inline

construct quaternion from axis and rotation angle

Definition at line 56 of file quaternion.h.

References cgv::math::quaternion< T >::set().

◆ quaternion() [6/8]

template<typename T >
template<class rot_mat_type >
cgv::math::quaternion< T >::quaternion ( const rot_mat_type &  matrix)
inline

construct quaternion from 3x3 rotation or rotational part of homogeneous 3x4 / 4x4 matrix

Definition at line 59 of file quaternion.h.

References cgv::math::quaternion< T >::set().

◆ quaternion() [7/8]

template<typename T >
cgv::math::quaternion< T >::quaternion ( coord_type  w,
coord_type  x,
coord_type  y,
coord_type  z 
)
inline

◆ quaternion() [8/8]

template<typename T >
cgv::math::quaternion< T >::quaternion ( coord_type  re,
const vec_type im 
)
inline

construct quaternion from real part and vector

Definition at line 63 of file quaternion.h.

References cgv::math::quaternion< T >::im(), cgv::math::quaternion< T >::re(), and cgv::math::quaternion< T >::set().

Member Function Documentation

◆ affin() [1/2]

template<typename T >
void cgv::math::quaternion< T >::affin ( const quaternion< T > &  p,
coord_type  t,
const quaternion< T > &  q 
)
inline

◆ affin() [2/2]

template<typename T >
void cgv::math::quaternion< T >::affin ( coord_type  s,
const quaternion< T > &  q 
)
inline

compute affin combination with angular interpolation

Definition at line 270 of file quaternion.h.

References cgv::math::quaternion< T >::affin().

◆ apply()

template<typename T >
vec_type cgv::math::quaternion< T >::apply ( const vec_type v) const
inline

◆ conj()

template<typename T >
quaternion< T > cgv::math::quaternion< T >::conj ( ) const
inline

return the conjugate

Definition at line 224 of file quaternion.h.

References cgv::math::quaternion< T >::im(), and cgv::math::quaternion< T >::re().

◆ conjugate()

template<typename T >
void cgv::math::quaternion< T >::conjugate ( )
inline

◆ exp()

template<typename T >
quaternion< T > cgv::math::quaternion< T >::exp ( ) const
inline

◆ get_homogeneous_matrix()

template<typename T >
hmat_type cgv::math::quaternion< T >::get_homogeneous_matrix ( ) const
inline

return equivalent 4x4 rotation matrix

Definition at line 169 of file quaternion.h.

References cgv::math::quaternion< T >::put_homogeneous_matrix().

Referenced by cgv::app::gizmo::finish_frame().

◆ get_matrix()

template<typename T >
mat_type cgv::math::quaternion< T >::get_matrix ( ) const
inline

return equivalent 3x3 rotation matrix

Definition at line 152 of file quaternion.h.

References cgv::math::quaternion< T >::put_matrix().

◆ get_rotated() [1/2]

template<typename T >
mat_type cgv::math::quaternion< T >::get_rotated ( const mat_type M) const
inline

Rotate source frame s into destination frame d.

Definition at line 209 of file quaternion.h.

References cgv::math::quaternion< T >::rotate().

◆ get_rotated() [2/2]

template<typename T >
vec_type cgv::math::quaternion< T >::get_rotated ( const vec_type v) const
inline

return rotated vector

Definition at line 200 of file quaternion.h.

References cgv::math::quaternion< T >::put_image().

Referenced by cgv::math::pose_transform_point(), and cgv::math::quaternion< T >::rotate().

◆ im()

◆ inverse()

template<typename T >
quaternion< T > cgv::math::quaternion< T >::inverse ( ) const
inline

return the inverse

Definition at line 232 of file quaternion.h.

References cgv::math::quaternion< T >::invert().

Referenced by cgv::math::rigid_transform< T >::inverse().

◆ inverse_rotate()

template<typename T >
void cgv::math::quaternion< T >::inverse_rotate ( vec_type image) const
inline

rotate vector according to the inverse quaternion

Definition at line 217 of file quaternion.h.

References cgv::math::quaternion< T >::put_preimage().

Referenced by cgv::app::gizmo::handle().

◆ invert()

◆ log()

◆ negate()

template<typename T >
void cgv::math::quaternion< T >::negate ( )
inline

negate the quaternion

Definition at line 228 of file quaternion.h.

References cgv::math::quaternion< T >::conjugate(), and cgv::math::quaternion< T >::re().

◆ negated()

template<typename T >
quaternion< T > cgv::math::quaternion< T >::negated ( ) const
inline

return the negated quaternion

Definition at line 226 of file quaternion.h.

References cgv::math::quaternion< T >::im(), and cgv::math::quaternion< T >::re().

Referenced by cgv::math::quaternion< T >::operator-().

◆ operator*() [1/2]

template<typename T >
quaternion< T > cgv::math::quaternion< T >::operator* ( const quaternion< T > &  q) const
inline

field multiplication

Definition at line 292 of file quaternion.h.

◆ operator*() [2/2]

template<typename T >
quaternion< T > cgv::math::quaternion< T >::operator* ( const T &  s) const
inline

multiplication with scalar s

Definition at line 296 of file quaternion.h.

◆ operator*=() [1/2]

◆ operator*=() [2/2]

template<typename T >
quaternion< T > & cgv::math::quaternion< T >::operator*= ( const T &  s)
inline

in place multiplication with s

Definition at line 294 of file quaternion.h.

◆ operator-()

template<typename T >
quaternion< T > cgv::math::quaternion< T >::operator- ( ) const
inline

negation operator

Definition at line 272 of file quaternion.h.

References cgv::math::quaternion< T >::negated().

◆ operator=()

template<typename T >
quaternion< T > & cgv::math::quaternion< T >::operator= ( const quaternion< T > &  quat)
inline

assignement operator

Definition at line 49 of file quaternion.h.

◆ put_axis()

template<typename T >
coord_type cgv::math::quaternion< T >::put_axis ( vec_type v) const
inline

◆ put_homogeneous_matrix()

template<typename T >
void cgv::math::quaternion< T >::put_homogeneous_matrix ( hmat_type M) const
inline

◆ put_im()

template<typename T >
void cgv::math::quaternion< T >::put_im ( vec_type vector) const
inline

◆ put_image()

template<typename T >
void cgv::math::quaternion< T >::put_image ( const vec_type preimage,
vec_type image 
) const
inline

◆ put_matrix()

◆ put_normal()

template<typename T >
void cgv::math::quaternion< T >::put_normal ( coord_type n)
inline

◆ put_preimage()

template<typename T >
void cgv::math::quaternion< T >::put_preimage ( const vec_type image,
vec_type preimage 
) const
inline

rotate image according to quaternion into preimage

Definition at line 211 of file quaternion.h.

References cgv::math::quaternion< T >::im(), and cgv::math::quaternion< T >::re().

Referenced by cgv::math::quaternion< T >::inverse_rotate().

◆ re() [1/2]

template<typename T >
coord_type & cgv::math::quaternion< T >::re ( )
inline

return reference to real part

Definition at line 303 of file quaternion.h.

References cgv::math::fvec< T, 4 >::w().

◆ re() [2/2]

◆ rotate() [1/2]

template<typename T >
void cgv::math::quaternion< T >::rotate ( mat_type m) const
inline

Rotate a frame according to quaternion.

Definition at line 202 of file quaternion.h.

References cgv::math::fmat< T, N, M >::col(), cgv::math::quaternion< T >::get_rotated(), and cgv::math::fmat< T, N, M >::set_col().

◆ rotate() [2/2]

template<typename T >
void cgv::math::quaternion< T >::rotate ( vec_type v) const
inline

◆ set() [1/6]

◆ set() [2/6]

template<typename T >
void cgv::math::quaternion< T >::set ( const quaternion< T > &  quat)
inline

setter from quaternion

Definition at line 83 of file quaternion.h.

◆ set() [3/6]

template<typename T >
template<class rot_mat_type >
void cgv::math::quaternion< T >::set ( const rot_mat_type &  M)
inline

set quaternion from 3x3 rotation or rotational part of homogeneous 3x4 / 4x4 matrix

Definition at line 86 of file quaternion.h.

References cgv::math::fvec< T, 4 >::w(), cgv::math::fvec< T, 4 >::x(), cgv::math::fvec< T, 4 >::y(), and cgv::math::fvec< T, 4 >::z().

◆ set() [4/6]

template<typename T >
void cgv::math::quaternion< T >::set ( const vec_type axis,
coord_type  angle 
)
inline

set quaternion from axis and rotation angle

Definition at line 77 of file quaternion.h.

References cgv::math::quaternion< T >::set().

◆ set() [5/6]

template<typename T >
void cgv::math::quaternion< T >::set ( coord_type  re,
const vec_type im 
)
inline

◆ set() [6/6]

template<typename T >
void cgv::math::quaternion< T >::set ( coord_type  re,
coord_type  ix,
coord_type  iy,
coord_type  iz 
)
inline

◆ set_normal()

template<typename T >
void cgv::math::quaternion< T >::set_normal ( const vec_type n)
inline

initialize quaternion from normal vector

Definition at line 171 of file quaternion.h.

References cgv::math::quaternion< T >::set(), cgv::math::fvec< T, N >::x(), cgv::math::fvec< T, N >::y(), and cgv::math::fvec< T, N >::z().

◆ vec() [1/2]

template<typename T >
base_type & cgv::math::quaternion< T >::vec ( )
inline

Definition at line 64 of file quaternion.h.

◆ vec() [2/2]

template<typename T >
const base_type & cgv::math::quaternion< T >::vec ( ) const
inline

Definition at line 65 of file quaternion.h.


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