vmath vmath-0.11

Public Member Functions | Static Public Member Functions | Public Attributes | Friends | List of all members
Quaternion< T > Class Template Reference

Quaternion class implementing some quaternion algebra operations. More...

`#include <vmath.h>`

Collaboration diagram for Quaternion< T >:
[legend]

## Public Member Functions
| Quaternion ()
| Quaternion constructor, sets quaternion to (0 + 0i + 0j + 0k). More...
| Quaternion (const Quaternion< T > &q)
| Copy constructor. More...
template<class FromT >
| Quaternion (const Quaternion< FromT > &q)
| Copy casting constructor. More...
| Quaternion (T w_, const Vector3< T > &v_)
| Creates quaternion object from real part w_ and complex part v_. More...
| Quaternion (T w_, T x, T y, T z)
| Creates quaternion object from value (w_ + xi + yj + zk). More...
Quaternion< T > & | operator= (const Quaternion< T > &rhs)
| Copy operator. More...
template<class FromT >
Quaternion< T > & | operator= (const Quaternion< FromT > &rhs)
| Copy convert operator. More...
Quaternion< T > | operator+ (const Quaternion< T > &rhs) const
| Addition operator. More...
Quaternion< T > | operator* (const Quaternion< T > &rhs) const
| Multiplication operator. More...
Quaternion< T > | operator* (T rhs) const
| Multiplication operator. More...
Quaternion< T > | operator- (const Quaternion< T > &rhs) const
| Subtraction operator. More...
Quaternion< T > & | operator+= (const Quaternion< T > &rhs)
| Addition operator. More...
Quaternion< T > & | operator-= (const Quaternion< T > &rhs)
| Subtraction operator. More...
Quaternion< T > & | operator*= (const Quaternion< T > &rhs)
| Multiplication operator. More...
Quaternion< T > & | operator*= (T rhs)
| Multiplication operator. More...
bool | operator== (const Quaternion< T > &rhs) const
| Equality test operator. More...
bool | operator!= (const Quaternion< T > &rhs) const
| Inequality test operator. More...
Quaternion< T > | operator- () const
| Unary negate operator. More...
Quaternion< T > | operator~ () const
| Unary conjugate operator. More...
T | length () const
| Get lenght of quaternion. More...
T | lengthSq () const
| Return square of length. More...
void | normalize ()
| Normalize quaternion. More...
Matrix3< T > | rotMatrix ()
| Converts quaternion into rotation matrix. More...
Matrix4< T > | transform () const
| Converts quaternion into transformation matrix. More...
Quaternion< T > | lerp (T fact, const Quaternion< T > &rhs) const
| Linear interpolation of two quaternions. More...
std::string | toString () const
| Gets string representation. More...
Quaternion< T > | slerp (T r, const Quaternion< T > &q2) const
| Computes spherical interpolation between quaternions (this, q2) using coefficient of interpolation r (in [0, 1]). More...

## Static Public Member Functions
static Quaternion< T > | fromEulerAngles (T x, T y, T z)
| Creates quaternion for eulers angles. More...
static Quaternion< T > | fromAxisRot (Vector3< T > axis, float angleDeg)
| Creates quaternion as rotation around axis. More...
static Quaternion< T > | fromMatrix (const Matrix4< T > &m)
| Creates quaternion from transform matrix. More...
static Quaternion< T > | fromMatrix (const Matrix3< T > &m)
| Creates quaternion from rotation matrix. More...

## Public Attributes
T | w
| Real part of quaternion. More...
Vector3< T > | v
| Imaginary part of quaternion. More...

## Friends
std::ostream & | operator<< (std::ostream &oss, const Quaternion< T > &q)
| Provides output to standard output stream. More...

## Detailed Description

### template<class T>
class Quaternion< T >

Quaternion class implementing some quaternion algebra operations.

Quaternion is kind of complex number it consists of its real part (w) and its complex part v. This complex part has three elements, so we can express it as xi + yj + zk . Note that coordinates of (x,y,z) are hold inside v field.

## Constructor & Destructor Documentation

## ◆ Quaternion() [1/5]

template<class T>

Quaternion< T >::Quaternion | ( |  | ) |
| inline

Quaternion constructor, sets quaternion to (0 + 0i + 0j + 0k).

## ◆ Quaternion() [2/5]

template<class T>

Quaternion< T >::Quaternion | ( | const Quaternion< T > & | q | ) |
| inline

Copy constructor.

## ◆ Quaternion() [3/5]

template<class T>
template<class FromT >

Quaternion< T >::Quaternion | ( | const Quaternion< FromT > & | q | ) |
| inline

Copy casting constructor.

## ◆ Quaternion() [4/5]

template<class T>

Quaternion< T >::Quaternion | ( | T | w_,
|  | const Vector3< T > & | v_
| ) |  |
| inline

Creates quaternion object from real part w_ and complex part v_.

Parameters

  w_ | Real part of quaternion.
  v_ | Complex part of quaternion (xi + yj + zk).

## ◆ Quaternion() [5/5]

template<class T>

Quaternion< T >::Quaternion | ( | T | w_,
|  | T | x,
|  | T | y,
|  | T | z
| ) |  |
| inline

Creates quaternion object from value (w_ + xi + yj + zk).

Parameters

  w_ | Real part of quaternion.
  x | Complex coefficient for i complex constant.
  y | Complex coefficient for j complex constant.
  z | Complex coefficient for k complex constant.

## Member Function Documentation

## ◆ fromAxisRot()

template<class T>

static Quaternion<T> Quaternion< T >::fromAxisRot | ( | Vector3< T > | axis,
|  | float | angleDeg
| ) |  |
| inline static

Creates quaternion as rotation around axis.

Parameters

  axis | Unit vector expressing axis of rotation.
  angleDeg | Angle of rotation around axis (in degrees).

## ◆ fromEulerAngles()

template<class T>

static Quaternion<T> Quaternion< T >::fromEulerAngles | ( | T | x,
|  | T | y,
|  | T | z
| ) |  |
| inline static

Creates quaternion for eulers angles.

Parameters

  x | Rotation around x axis (in degrees).
  y | Rotation around y axis (in degrees).
  z | Rotation around z axis (in degrees).

Returns
  Quaternion object representing transformation.

## ◆ fromMatrix() [1/2]

template<class T>

static Quaternion<T> Quaternion< T >::fromMatrix | ( | const Matrix4< T > & | m | ) |
| inline static

Creates quaternion from transform matrix.

Parameters

  m | Transform matrix used to compute quaternion.

Returns
  Quaternion representing rotation of matrix m.

## ◆ fromMatrix() [2/2]

template<class T>

static Quaternion<T> Quaternion< T >::fromMatrix | ( | const Matrix3< T > & | m | ) |
| inline static

Creates quaternion from rotation matrix.

Parameters

  m | Rotation matrix used to compute quaternion.

Returns
  Quaternion representing rotation of matrix m.

## ◆ length()

template<class T>

T Quaternion< T >::length | ( |  | ) | const
| inline

Get lenght of quaternion.

Returns
  Length of quaternion.

## ◆ lengthSq()

template<class T>

T Quaternion< T >::lengthSq | ( |  | ) | const
| inline

Return square of length.

Returns
  length ^ 2

Note
  This method is faster then length(). For comparison of length of two quaternion can be used just this value, instead of more expensive length() method.

## ◆ lerp()

template<class T>

Quaternion<T> Quaternion< T >::lerp | ( | T | fact,
|  | const Quaternion< T > & | rhs
| ) |  | const
| inline

Linear interpolation of two quaternions.

Parameters

  fact | Factor of interpolation. For translation from position of this vector to quaternion rhs, values of factor goes from 0.0 to 1.0.
  rhs | Second Quaternion for interpolation

Note
  However values of fact parameter are reasonable only in interval [0.0 , 1.0], you can pass also values outside of this interval and you can get result (extrapolation?)

## ◆ normalize()

template<class T>

void Quaternion< T >::normalize | ( |  | ) |
| inline

Normalize quaternion.

## ◆ operator!=()

template<class T>

bool Quaternion< T >::operator!= | ( | const Quaternion< T > & | rhs | ) | const
| inline

Inequality test operator.

Parameters

  rhs | Right hand side argument of binary operator.

Returns
  not (lhs == rhs) :-P

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

template<class T>

Quaternion<T> Quaternion< T >::operator* | ( | const Quaternion< T > & | rhs | ) | const
| inline

Multiplication operator.

Parameters

  rhs | Right hand side argument of binary operator.

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

template<class T>

Quaternion<T> Quaternion< T >::operator* | ( | T | rhs | ) | const
| inline

Multiplication operator.

Parameters

  rhs | Right hand side argument of binary operator.

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

template<class T>

Quaternion<T>& Quaternion< T >::operator*= | ( | const Quaternion< T > & | rhs | ) |
| inline

Multiplication operator.

Parameters

  rhs | Right hand side argument of binary operator.

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

template<class T>

Quaternion<T>& Quaternion< T >::operator*= | ( | T | rhs | ) |
| inline

Multiplication operator.

Parameters

  rhs | Right hand side argument of binary operator.

## ◆ operator+()

template<class T>

Quaternion<T> Quaternion< T >::operator+ | ( | const Quaternion< T > & | rhs | ) | const
| inline

Addition operator.

Parameters

  rhs | Right hand side argument of binary operator.

## ◆ operator+=()

template<class T>

Quaternion<T>& Quaternion< T >::operator+= | ( | const Quaternion< T > & | rhs | ) |
| inline

Addition operator.

Parameters

  rhs | Right hand side argument of binary operator.

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

template<class T>

Quaternion<T> Quaternion< T >::operator- | ( | const Quaternion< T > & | rhs | ) | const
| inline

Subtraction operator.

Parameters

  rhs | Right hand side argument of binary operator.

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

template<class T>

Quaternion<T> Quaternion< T >::operator- | ( |  | ) | const
| inline

Unary negate operator.

Returns
  negated quaternion

## ◆ operator-=()

template<class T>

Quaternion<T>& Quaternion< T >::operator-= | ( | const Quaternion< T > & | rhs | ) |
| inline

Subtraction operator.

Parameters

  rhs | Right hand side argument of binary operator.

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

template<class T>

Quaternion<T>& Quaternion< T >::operator= | ( | const Quaternion< T > & | rhs | ) |
| inline

Copy operator.

Parameters

  rhs | Right hand side argument of binary operator.

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

template<class T>
template<class FromT >

Quaternion<T>& Quaternion< T >::operator= | ( | const Quaternion< FromT > & | rhs | ) |
| inline

Copy convert operator.

Parameters

  rhs | Right hand side argument of binary operator.

## ◆ operator==()

template<class T>

bool Quaternion< T >::operator== | ( | const Quaternion< T > & | rhs | ) | const
| inline

Equality test operator.

Parameters

  rhs | Right hand side argument of binary operator.

Note
  Test of equality is based of threshold EPSILON value. To be two values equal, must satisfy this condition | lhs - rhs | < EPSILON, for all quaternion coordinates.

## ◆ operator~()

template<class T>

Quaternion<T> Quaternion< T >::operator~ | ( |  | ) | const
| inline

Unary conjugate operator.

Returns
  conjugated quaternion

## ◆ rotMatrix()

template<class T>

Matrix3<T> Quaternion< T >::rotMatrix | ( |  | ) |
| inline

Converts quaternion into rotation matrix.

Returns
  Rotation matrix expressing this quaternion.

## ◆ slerp()

template<class T>

Quaternion<T> Quaternion< T >::slerp | ( | T | r,
|  | const Quaternion< T > & | q2
| ) |  | const
| inline

Computes spherical interpolation between quaternions (this, q2) using coefficient of interpolation r (in [0, 1]).

Parameters

  r | The ratio of interpolation form this (r = 0) to q2 (r = 1).
  q2 | Second quaternion for interpolation.

Returns
  Result of interpolation.

## ◆ toString()

template<class T>

std::string Quaternion< T >::toString | ( |  | ) | const
| inline

Gets string representation.

## ◆ transform()

template<class T>

Matrix4<T> Quaternion< T >::transform | ( |  | ) | const
| inline

Converts quaternion into transformation matrix.

Note
  This method performs same operation as rotMatrix() conversion method. But returns Matrix of 4x4 elements.

Returns
  Transformation matrix expressing this quaternion.

## Friends And Related Function Documentation

## ◆ operator<<

template<class T>

std::ostream& operator<< | ( | std::ostream & | oss,
|  | const Quaternion< T > & | q
| ) |  |
| friend

Provides output to standard output stream.

## Member Data Documentation

## ◆ v

template<class T>

Vector3<T> Quaternion< T >::v

Imaginary part of quaternion.

## ◆ w

template<class T>

T Quaternion< T >::w

Real part of quaternion.

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

- src/vmath.h