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 ()
 standard constructor initializes to unit quaternion
 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)
 assignment 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_type & vec ()
const base_type & vec () 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_type & re ()
 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
 fvec (const T &x, const T &y)
 construct and initialize the first two components to the given values
 fvec (const T &x, const T &y, const T &z)
 construct and initialize the first three components to the given values
 fvec (const T &x, const T &y, const T &z, const T &w)
 construct and initialize the first four components to the given values
 fvec (cgv::type::uint32_type n, const T *a)
 create a vector from an array of size n; if n is less than N the remaining N-n components are set to zero
 fvec (cgv::type::uint32_type n, const S *a)
 create a vector from an array of size n of a different type; if n is less than N the remaining N-n components are set to zero
 fvec (const fvec< S, N > &other)
 construct by copy from a vector of a different type
 fvec (const fvec< S1, N - 1 > &other, S2 s)
 construct from a vector of one dimension less plus a scalar
 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
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 &x)
 fill the vector with constant value x
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
fvec< T, N - 1 > clip () const
 convert back from homogeneous representation by performing a w-clip
const fvec< T, N - 1 > & down () const
 provide const reference to vector where last dimension is dropped
fvec< T, N - 1 > & down ()
 provide reference to vector where last dimension is dropped
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
iterator end ()
 return an iterator past the last component of *this
const_iterator begin () const
 return an iterator to the first 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
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 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
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 T &s)
 in place subtraction by scalar s
fvec< T, N > & operator*= (const T &s)
 in place multiplication with s
fvec< T, N > & operator/= (const T &s)
 in place division by scalar s
fvec< T, N > & operator+= (const fvec< S, N > &v)
 in place vector addition
fvec< T, N > & operator-= (const fvec< S, N > &v)
 in place vector subtraction
fvec< T, N > & operator*= (const fvec< S, N > &v)
 in place componentwise vector multiplication
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 fvec< S, N > &v) const
 vector subtraction
fvec< T, N > operator* (const fvec< S, N > &v) const
 componentwise vector multiplication
fvec< T, N > operator/ (const fvec< S, N > &v) const
 componentwise vector division
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 T &s) const
 multiplication with scalar s
fvec< T, N > operator/ (const T &s) const
 divide vector by scalar s
fvec< T, N > operator- () const
 negate the vector
bool operator== (const fvec< S, N > &v) const
 test for equality
bool operator!= (const fvec< S, N > &v) const
 test for unequal
bool operator< (const fvec< S, N > &v) const
 define smaller operator based on component comparison with significance increasing from 0 to N-1, such that fvec can be used as keys in maps
T sqr_length () const
 square length of vector
T length () const
 length of the vector L2-Norm
void sign ()
 componentwise sign values
void step (const fvec< T, N > &r)
 componentwise step function using stored values as edge
void abs ()
 componentwise absolute values
void ceil ()
 ceil componentwise
void floor ()
 floor componentwise
void round ()
 round componentwise
T normalize ()
 normalize the vector using the L2-Norm and return the length
T 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 >
T 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.

Referenced by cgv::math::quaternion< float >::conj(), cgv::math::quaternion< float >::log(), and cgv::math::quaternion< float >::negated().

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

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

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

◆ quaternion() [7/8]

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

construct quaternion directly

Definition at line 61 of file quaternion.h.

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

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

compute affin combination with angular interpolation

Definition at line 244 of file quaternion.h.

Referenced by cgv::math::quaternion< float >::affin().

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

◆ apply()

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

rotate vector according to quaternion

Definition at line 219 of file quaternion.h.

◆ conj()

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

return the conjugate

Definition at line 224 of file quaternion.h.

◆ conjugate()

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

compute conjugate

Definition at line 230 of file quaternion.h.

Referenced by cgv::math::quaternion< float >::invert(), and cgv::math::quaternion< float >::negate().

◆ exp()

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

exponential map

Definition at line 330 of file quaternion.h.

Referenced by cgv::math::quaternion< float >::exp().

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

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

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

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

Referenced by cgv::math::pose_transform_point(), and cgv::math::quaternion< float >::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.

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

◆ invert()

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

compute inverse

Definition at line 234 of file quaternion.h.

Referenced by cgv::math::quaternion< float >::inverse().

◆ log()

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

logarithmic map

Definition at line 338 of file quaternion.h.

◆ negate()

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

negate the quaternion

Definition at line 228 of file quaternion.h.

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

Referenced by cgv::math::quaternion< float >::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]

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

field multiplication

Definition at line 274 of file quaternion.h.

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

◆ operator=()

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

assignment 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 rotation axis and return rotation angle

Definition at line 309 of file quaternion.h.

Referenced by cgv::math::quaternion< float >::put_axis().

◆ put_homogeneous_matrix()

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

compute equivalent homogeneous 4x4 rotation matrix

Definition at line 154 of file quaternion.h.

Referenced by cgv::math::quaternion< float >::get_homogeneous_matrix(), and cgv::math::random::uniform_orientation().

◆ put_im()

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

put imaginary part

Definition at line 305 of file quaternion.h.

◆ put_image()

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

rotate preimage according to quaternion into image

Definition at line 192 of file quaternion.h.

Referenced by cgv::math::quaternion< float >::apply(), cgv::math::quaternion< float >::get_rotated(), and cgv::math::quaternion< float >::rotate().

◆ put_matrix()

◆ put_normal()

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

extract normal vector

Definition at line 185 of file quaternion.h.

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

Referenced by cgv::math::quaternion< float >::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.

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

◆ rotate() [2/2]

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

rotate vector according to quaternion

Definition at line 198 of file quaternion.h.

Referenced by cgv::math::quaternion< float >::get_rotated().

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

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

◆ set() [5/6]

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

set quaternion from real part and vector

Definition at line 131 of file quaternion.h.

◆ 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 quaternion directly

Definition at line 123 of file quaternion.h.

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

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