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 >
iterator begin ()
 
const_iterator begin () const
 
iterator end ()
 
const_iterator end () const
 
reverse_iterator rbegin ()
 
const_reverse_iterator rbegin () const
 
reverse_iterator rend ()
 
const_reverse_iterator rend () const
 reverse iterator pointing to the end of reverse iteration
 
 fvec ()
 creates a vector not initialized
 
 fvec (const T &a)
 creates a vector, where all N components are initialized to the constant value a
 
 fvec (const T &x, const T &y)
 construct and init first two coordinates to the given values
 
 fvec (const T &x, const T &y, const T &z)
 construct and init first three coordinates to the given values
 
 fvec (const T &x, const T &y, const T &z, const T &w)
 construct and init first four coordinates to the given values
 
 fvec (cgv::type::uint32_type n, const T *a)
 creates a vector from a n-element array a, if n < N remaining N-n elements are set to zero
 
 fvec (cgv::type::uint32_type n, const S *a)
 creates a column vector initialized to array of a different type with zeros filled to not copied components
 
 fvec (const fvec< T, N > &rhs)
 copy constructor
 
 fvec (const fvec< S, N > &fv)
 copies a column vector of a different type
 
 fvec (const fvec< S1, N - 1 > &fv, S2 w)
 construct from vector of one dimension less plus a scalar
 
 fvec (const fvec< S, N+1 > &fv)
 construct from vector of one dimension higher by cutting of the highest dimension
 
 fvec (const std::array< T, N > &arr)
 construct from std::array of same size
 
fvecoperator= (const fvec< T, N > &rhs)
 assign vector rhs, if vector and rhs have different sizes, vector has been resized to match the size of
 
fvecoperator= (const T &a)
 set all components of vector to constant value a
 
void assign (const std::array< T, N > &arr)
 set to the contents of the given std::array with same size
 
void set (const T &x, const T &y)
 set the first two components
 
void set (const T &x, const T &y, const T &z)
 set the first three components
 
void set (const T &x, const T &y, const T &z, const T &w)
 set the first four components
 
void fill (const T &a)
 fill elements of vector with scalar v
 
void zeros ()
 fill the vector with zeros
 
void zerosh ()
 fill the vector with zeros except for the last component, which will be set to one
 
void ones ()
 fill the vector with ones
 
fvec< T, N+1 > lift () const
 convert to homogeneous version by adding a 1
 
vec< T > to_vec () const
 conversion to vector type
 
T & x ()
 first element
 
const T & x () const
 first element of const vector
 
T & y ()
 second element
 
const T & y () const
 second element of const vector
 
T & z ()
 third element
 
const T & z () const
 third element of const vector
 
T & w ()
 fourth element
 
const T & w () const
 fourth element of const vector
 
T & operator() (const int i)
 access i'th element
 
const T & operator() (const int i) const
 access i'th element of const vector
 
T & operator[] (const int i)
 access i'th element
 
const T & operator[] (const int i) const
 access i'th element of const vector
 
T * data ()
 cast into array. This allows calls like glVertex<N><T>v(p.data()) instead of glVertex<N><T,N>(p.x(),p.y(),....)
 
const T * data () const
 cast into const array
 
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 T &s) const
 componentwise subtraction of scalar
 
fvec< T, N > operator- (const fvec< S, N > &v) const
 vector subtraction
 
fvec< T, N > operator- (void) const
 negates 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
 divides 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
 
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
 
sqr_length () const
 square length of vector
 
normalize ()
 normalize the vector using the L2-Norm and return the length
 
safe_normalize ()
 normalize the vector if length is not zero using the L2-Norm and return the length
 

Additional Inherited Members

- Static Public Member Functions inherited from cgv::math::fvec< T, 4 >
static fvec< T, N > zeroh ()
 creates 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 elements
 
- 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- ( void  ) 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.

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

◆ 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: