LinearAlgebra
 All Classes Namespaces Files Functions Variables Typedefs Macros
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
a3d::Quaternion< T, M > Struct Template Reference

A quaternion struct primarily for rotation representations and calculations. More...

Collaboration diagram for a3d::Quaternion< T, M >:
Collaboration graph
[legend]

Public Member Functions

 Quaternion ()
 Creates an uninitialized quaternion. More...
 
 Quaternion (int i)
 Creates a quaternion initialized to zero rotation. More...
 
template<class S >
 Quaternion (S s, S vi, S vj, S vk)
 Creates a quaternion from the specified real and imaginary parts. More...
 
template<class S , class T2 , class M2 >
 Quaternion (S s, const Vector3< T2, M2 > &v)
 Creates a quaternion from the specified real and imaginary parts. More...
 
template<class S , class T2 , class M2 >
 Quaternion (const Vector3< T2, M2 > &v, S s)
 Creates a quaternion from the specified real and imaginary parts. More...
 
template<class T2 , class M2 >
 Quaternion (const Quaternion< T2, M2 > &q)
 Copies a quaternion. More...
 
template<class T2 , class M2 >
 Quaternion (const Rotation< T2, M2 > &r)
 Cast from rotation. More...
 
template<class T2 , class M2 >
 Quaternion (const Vector3< T2, M2 > &v)
 Casting from vector to quaternion. More...
 
template<class T2 , class M2 >
 Quaternion (const Matrix3< T2, M2 > &m)
 Casting from matrix. More...
 
Quaternion< T, M > & operator= (const Quaternion< T, M > &o)
 Copy operator. More...
 
template<class T2 , class M2 >
Quaternion< T, M > & operator= (const Quaternion< T2, M2 > &o)
 Copy operator. More...
 
Quaternion< T, M > operator- () const
 Negating quaternion. More...
 
Quaternion< T, M > slerp (const Quaternion< T, M > &q, double t)
 Spherical linear interpolation between this and the provided quaternion. More...
 
Quaternion< T, M > slerp (double t)
 Spherical linear interpolation from zero rotation to this. More...
 
template<class T2 , class M2 >
Vector3< T, M > rotate (const Vector3< T2, M2 > &v) const
 Rotate a vector using this quaternion. More...
 
template<class T2 , class M2 >
Vector4< T, M > rotate (const Vector4< T2, M2 > &v) const
 Rotate a vector using this quaternion. More...
 
Quaternion< T, M > conjugate () const
 Returns the quaternion conjugate. More...
 
Quaternion< T, M > inverse () const
 Returns the quaternion inverse. More...
 
norm () const
 Returns the norm of this quaternion. More...
 
Quaternion< T, M > unit () const
 Return a unit version of this quaternion. More...
 

Static Public Member Functions

template<class S , class T2 , class M2 >
static Quaternion< T, M > fromAxisAngle (const Vector3< T2, M2 > &v, S a)
 Creates a quaternion from an axis and an angle of rotation around this axis. More...
 
template<class T2 , class M2 , class T3 , class M3 >
static Quaternion< T, M > fromVectorPair (const Vector3< T2, M2 > &x, const Vector3< T3, M3 > &y)
 Create the quaternion that would rotate a specified unit vector to the other specified unit vector. More...
 
template<class T2 , class M2 , class T3 , class M3 , class T4 , class M4 , class T5 , class M5 >
static Quaternion< T, M > fromAnglePair (const Vector3< T2, M2 > &x0, const Vector3< T3, M3 > &y0, const Vector3< T4, M4 > &x1, const Vector3< T5, M5 > &y1)
 Create the quaternion that would rotate a specified angle of unit vectors into the other specified angle of unit vectors. More...
 
template<class T2 , class M2 >
static Quaternion< T, M > fromEulerAngles (Vector3< T2, M2 > &v)
 Create a quaternion from Euler angles. More...
 

Public Attributes

s
 The real part of the quaternion. More...
 
Vector3< T, M > v
 The imaginary part of the quaternion. More...
 

Detailed Description

template<class T, class M = Math<T>>
struct a3d::Quaternion< T, M >

A quaternion struct primarily for rotation representations and calculations.

This implementation, however, can also be used for real four dimensional complex calculations. All operators are correctly implemented, so take care. The inverse and negation does not always give the result people think they should.

Constructor & Destructor Documentation

template<class T, class M = Math<T>>
a3d::Quaternion< T, M >::Quaternion ( )
inline

Creates an uninitialized quaternion.

template<class T, class M = Math<T>>
a3d::Quaternion< T, M >::Quaternion ( int  i)
inlineexplicit

Creates a quaternion initialized to zero rotation.

Observe that this is not the same as a zero quaternion.

template<class T, class M = Math<T>>
template<class S >
a3d::Quaternion< T, M >::Quaternion ( s,
vi,
vj,
vk 
)
inline

Creates a quaternion from the specified real and imaginary parts.

template<class T, class M = Math<T>>
template<class S , class T2 , class M2 >
a3d::Quaternion< T, M >::Quaternion ( s,
const Vector3< T2, M2 > &  v 
)
inline

Creates a quaternion from the specified real and imaginary parts.

template<class T, class M = Math<T>>
template<class S , class T2 , class M2 >
a3d::Quaternion< T, M >::Quaternion ( const Vector3< T2, M2 > &  v,
s 
)
inline

Creates a quaternion from the specified real and imaginary parts.

template<class T, class M = Math<T>>
template<class T2 , class M2 >
a3d::Quaternion< T, M >::Quaternion ( const Quaternion< T2, M2 > &  q)
inline

Copies a quaternion.

References a3d::Quaternion< T, M >::s, and a3d::Quaternion< T, M >::v.

template<class T, class M = Math<T>>
template<class T2 , class M2 >
a3d::Quaternion< T, M >::Quaternion ( const Rotation< T2, M2 > &  r)
inlineexplicit
template<class T, class M = Math<T>>
template<class T2 , class M2 >
a3d::Quaternion< T, M >::Quaternion ( const Vector3< T2, M2 > &  v)
inlineexplicit

Casting from vector to quaternion.

The vector becomes the complex part of the quaternion

template<class T, class M = Math<T>>
template<class T2 , class M2 >
a3d::Quaternion< T, M >::Quaternion ( const Matrix3< T2, M2 > &  m)
inlineexplicit

Casting from matrix.

References a3d::Quaternion< T, M >::s, and a3d::Quaternion< T, M >::v.

Member Function Documentation

template<class T, class M = Math<T>>
Quaternion<T,M> a3d::Quaternion< T, M >::conjugate ( ) const
inline
template<class T, class M = Math<T>>
template<class T2 , class M2 , class T3 , class M3 , class T4 , class M4 , class T5 , class M5 >
static Quaternion<T,M> a3d::Quaternion< T, M >::fromAnglePair ( const Vector3< T2, M2 > &  x0,
const Vector3< T3, M3 > &  y0,
const Vector3< T4, M4 > &  x1,
const Vector3< T5, M5 > &  y1 
)
inlinestatic

Create the quaternion that would rotate a specified angle of unit vectors into the other specified angle of unit vectors.

The result is unspecified if either vector is not of unit length or if the angle between the vector pairs differs.

Parameters
x0the first unit vector in the initial angle
x1the second unit vector in the initial angle
y0the first unit vector in the rotated angle
y1the second unit vector in the rotated angle

References a3d::Quaternion< T, M >::conjugate(), a3d::Quaternion< T, M >::fromVectorPair(), and a3d::Vector3< T, M >::normalized().

Here is the call graph for this function:

template<class T, class M = Math<T>>
template<class S , class T2 , class M2 >
static Quaternion<T,M> a3d::Quaternion< T, M >::fromAxisAngle ( const Vector3< T2, M2 > &  v,
a 
)
inlinestatic

Creates a quaternion from an axis and an angle of rotation around this axis.

The axis of rotation must be of unit length.

References a3d::Quaternion< T, M >::v.

template<class T, class M = Math<T>>
template<class T2 , class M2 >
static Quaternion<T,M> a3d::Quaternion< T, M >::fromEulerAngles ( Vector3< T2, M2 > &  v)
inlinestatic

Create a quaternion from Euler angles.

template<class T, class M = Math<T>>
template<class T2 , class M2 , class T3 , class M3 >
static Quaternion<T,M> a3d::Quaternion< T, M >::fromVectorPair ( const Vector3< T2, M2 > &  x,
const Vector3< T3, M3 > &  y 
)
inlinestatic

Create the quaternion that would rotate a specified unit vector to the other specified unit vector.

The result is unspecified if either vector is not of unit length.

Parameters
xthe initial unit vector
ythe rotated unit vector

References a3d::Vector3< T, M >::length().

Referenced by a3d::Quaternion< T, M >::fromAnglePair().

Here is the call graph for this function:

template<class T, class M = Math<T>>
Quaternion<T,M> a3d::Quaternion< T, M >::inverse ( ) const
inline

Returns the quaternion inverse.

If the quaternion is unit the result is equal to the conjugate, but this function is slightly slower than using the conjugate directly.

References A3D_WARNING_EXPENSIVE, a3d::Quaternion< T, M >::conjugate(), and a3d::Quaternion< T, M >::s.

Referenced by a3d::operator/().

Here is the call graph for this function:

template<class T, class M = Math<T>>
T a3d::Quaternion< T, M >::norm ( ) const
inline

Returns the norm of this quaternion.

References a3d::Quaternion< T, M >::conjugate(), and a3d::Quaternion< T, M >::s.

Referenced by a3d::Quaternion< T, M >::unit().

Here is the call graph for this function:

template<class T, class M = Math<T>>
Quaternion<T,M> a3d::Quaternion< T, M >::operator- ( ) const
inline

Negating quaternion.

Both real and imaginary parts are negated.

References a3d::Quaternion< T, M >::s, and a3d::Quaternion< T, M >::v.

template<class T, class M = Math<T>>
Quaternion<T,M>& a3d::Quaternion< T, M >::operator= ( const Quaternion< T, M > &  o)
inline

Copy operator.

References a3d::Quaternion< T, M >::s, and a3d::Quaternion< T, M >::v.

template<class T, class M = Math<T>>
template<class T2 , class M2 >
Quaternion<T,M>& a3d::Quaternion< T, M >::operator= ( const Quaternion< T2, M2 > &  o)
inline

Copy operator.

References a3d::Quaternion< T, M >::s, and a3d::Quaternion< T, M >::v.

template<class T, class M = Math<T>>
template<class T2 , class M2 >
Vector3<T,M> a3d::Quaternion< T, M >::rotate ( const Vector3< T2, M2 > &  v) const
inline

Rotate a vector using this quaternion.

For this to be correct the quaternion must be unit, which is usually true if only rotational operations have previously been performed.

References a3d::Quaternion< T, M >::conjugate().

Here is the call graph for this function:

template<class T, class M = Math<T>>
template<class T2 , class M2 >
Vector4<T,M> a3d::Quaternion< T, M >::rotate ( const Vector4< T2, M2 > &  v) const
inline

Rotate a vector using this quaternion.

For this to be correct the quaternion must be unit, which is usually true if only rotational operations have previously been performed.

References a3d::Quaternion< T, M >::conjugate(), and a3d::Quaternion< T, M >::v.

Here is the call graph for this function:

template<class T, class M = Math<T>>
Quaternion<T,M> a3d::Quaternion< T, M >::slerp ( const Quaternion< T, M > &  q,
double  t 
)
inline

Spherical linear interpolation between this and the provided quaternion.

The interpolation is specified through the t parameter in the interval [0,1].

References a3d::Quaternion< T, M >::s, and a3d::Quaternion< T, M >::v.

Referenced by a3d::Quaternion< T, M >::slerp().

template<class T, class M = Math<T>>
Quaternion<T,M> a3d::Quaternion< T, M >::slerp ( double  t)
inline

Spherical linear interpolation from zero rotation to this.

Use this function to scale the rotation defined by this quaternion. Using multiplication with a scalar value will not scale the rotation but the complex number.

References a3d::Quaternion< T, M >::slerp().

Here is the call graph for this function:

template<class T, class M = Math<T>>
Quaternion<T,M> a3d::Quaternion< T, M >::unit ( ) const
inline

Return a unit version of this quaternion.

References a3d::Quaternion< T, M >::norm(), a3d::Quaternion< T, M >::s, and a3d::Quaternion< T, M >::v.

Here is the call graph for this function:

Member Data Documentation

template<class T, class M = Math<T>>
T a3d::Quaternion< T, M >::s
template<class T, class M = Math<T>>
Vector3<T,M> a3d::Quaternion< T, M >::v