[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]

| Quaternion< ValueType > Class Template Reference |

`#include <vigra/quaternion.hxx>`

## Public Types

typedef ValueType const & | const_reference
typedef NormTraits< ValueType >::NormType | NormType
typedef ValueType & | reference
typedef NormTraits< ValueType >::SquaredNormType | SquaredNormType
typedef ValueType | value_type

## Public Member Functions

template<class MatrixType >
void | fillRotationMatrix (MatrixType &matrix) const
NormType | magnitude () const
bool | operator!= (Quaternion const &other) const
Quaternion & | operator*= (Quaternion const &other)
Quaternion & | operator*= (double scale)
Quaternion | operator+ () const
Quaternion & | operator+= (value_type const &w)
Quaternion & | operator+= (Quaternion const &other)
Quaternion | operator- () const
Quaternion & | operator-= (value_type const &w)
Quaternion & | operator-= (Quaternion const &other)
Quaternion & | operator/= (Quaternion const &other)
Quaternion & | operator/= (double scale)
Quaternion & | operator= (Quaternion const &other)
Quaternion & | operator= (ValueType w)
bool | operator== (Quaternion const &other) const
value_type & | operator[] (int index)
value_type | operator[] (int index) const
| Quaternion (ValueType w=0, ValueType x=0, ValueType y=0, ValueType z=0)
| Quaternion (ValueType w, const Vector &v)
| Quaternion (const Quaternion &q)
void | setV (const Vector &v)
void | setV (ValueType x, ValueType y, ValueType z)
void | setW (ValueType w)
SquaredNormType | squaredMagnitude () const
const Vector & | v () const
Vector & | v ()
ValueType | w () const
ValueType & | w ()

## Static Public Member Functions

static Quaternion | createRotation (double angle, const Vector &rotationAxis)

## Detailed Description

### template<class ValueType>
class vigra::Quaternion< ValueType >

Quaternion class.

Quaternions are mainly used as a compact representation for 3D rotations because they are much less prone to round-off errors than rotation matrices, especially when many rotations are concatenated. In addition, the angle/axis interpretation of normalized quaternions is very intuitive. Read the Wikipedia entry on quaternions for more information on the mathematics.

See also: Quaternion Operations

## Member Typedef Documentation

## ◆ value_type

typedef ValueType value_type

the quaternion's valuetype

## ◆ reference

typedef ValueType& reference

reference (return of operator[]).

## ◆ const_reference

typedef ValueType const& const_reference

const reference (return of operator[] const).

## ◆ SquaredNormType

typedef NormTraits<ValueType>::SquaredNormType SquaredNormType

the quaternion's squared norm type

## ◆ NormType

typedef NormTraits<ValueType>::NormType NormType

the quaternion's norm type

## Constructor & Destructor Documentation

## ◆ Quaternion() [1/3]

Quaternion | ( | ValueType | w = `0`,
|  | ValueType | x = `0`,
|  | ValueType | y = `0`,
|  | ValueType | z = `0`
| ) |  |

Construct a quaternion with explicit values for the real and imaginary parts.

## ◆ Quaternion() [2/3]

Quaternion | ( | ValueType | w,
|  | const Vector & | v
| ) |  |

Construct a quaternion with real value and imaginary vector.

Equivalent to `Quaternion(w, v[0], v[1], v[2])`.

## ◆ Quaternion() [3/3]

Quaternion | ( | const Quaternion< ValueType > & | q | ) |

Copy constructor.

## Member Function Documentation

## ◆ operator=() [1/2]

Quaternion& operator= | ( | Quaternion< ValueType > const & | other | ) |

Copy assignment.

## ◆ operator=() [2/2]

Quaternion& operator= | ( | ValueType | w | ) |

Assign w to the real part and set the imaginary part to zero.

## ◆ createRotation()

static Quaternion createRotation | ( | double | angle,
|  | const Vector & | rotationAxis
| ) |  |

static

Creates a Quaternion which represents the operation of rotating around the given axis by the given angle.

The angle should be in the range -pi..3*pi for sensible results.

## ◆ w() [1/2]

ValueType w | ( |  | ) | const

Read real part.

## ◆ w() [2/2]

ValueType& w | ( |  | ) |

Access real part.

## ◆ setW()

void setW | ( | ValueType | w | ) |

Set real part.

## ◆ v() [1/2]

const Vector& v | ( |  | ) | const

Read imaginary part.

## ◆ v() [2/2]

Vector& v | ( |  | ) |

Access imaginary part.

## ◆ setV() [1/2]

void setV | ( | const Vector & | v | ) |

Set imaginary part.

## ◆ setV() [2/2]

void setV | ( | ValueType | x,
|  | ValueType | y,
|  | ValueType | z
| ) |  |

Set imaginary part.

## ◆ operator[]() [1/2]

value_type& operator[] | ( | int | index | ) |

Access entry at index (0 <=> w(), 1 <=> v[0] etc.).

## ◆ operator[]() [2/2]

value_type operator[] | ( | int | index | ) | const

Read entry at index (0 <=> w(), 1 <=> v[0] etc.).

## ◆ magnitude()

NormType magnitude | ( |  | ) | const

Magnitude.

## ◆ squaredMagnitude()

SquaredNormType squaredMagnitude | ( |  | ) | const

Squared magnitude.

## ◆ operator+=() [1/2]

Quaternion& operator+= | ( | value_type const & | w | ) |

Add w to the real part.

If the quaternion represents a rotation, the rotation angle is increased by w.

## ◆ operator+=() [2/2]

Quaternion& operator+= | ( | Quaternion< ValueType > const & | other | ) |

Add assigment.

## ◆ operator-=() [1/2]

Quaternion& operator-= | ( | value_type const & | w | ) |

Subtract w from the real part.

If the quaternion represents a rotation, the rotation angle is decreased by w.

## ◆ operator-=() [2/2]

Quaternion& operator-= | ( | Quaternion< ValueType > const & | other | ) |

Subtract assigment.

## ◆ operator+()

Quaternion operator+ | ( |  | ) | const

Addition.

## ◆ operator-()

Quaternion operator- | ( |  | ) | const

Subtraction.

## ◆ operator*=() [1/2]

Quaternion& operator*= | ( | Quaternion< ValueType > const & | other | ) |

Multiply assignment.

If the quaternions represent rotations, the rotations of `this` and other are concatenated.

## ◆ operator*=() [2/2]

Quaternion& operator*= | ( | double | scale | ) |

Multiply all entries with the scalar scale.

## ◆ operator/=() [1/2]

Quaternion& operator/= | ( | Quaternion< ValueType > const & | other | ) |

Divide assignment.

## ◆ operator/=() [2/2]

Quaternion& operator/= | ( | double | scale | ) |

Devide all entries by the scalar scale.

## ◆ operator==()

bool operator== | ( | Quaternion< ValueType > const & | other | ) | const

Equal.

## ◆ operator!=()

bool operator!= | ( | Quaternion< ValueType > const & | other | ) | const

Not equal.

## ◆ fillRotationMatrix()

void fillRotationMatrix | ( | MatrixType & | matrix | ) | const

Fill the first 3x3 elements of the given matrix with a rotation matrix performing the same 3D rotation as this quaternion. If matrix is in column-major format, it should be pre-multiplied with the vectors to be rotated, i.e. matrix[0][0-3] will be the rotated X axis.

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

- vigra/quaternion.hxx

© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de) Heidelberg Collaboratory for Image Processing, University of Heidelberg, Germany | html generated using doxygen and Python vigra 1.11.0