Algebra3D
Algebra for 3D transformations
 All Classes Namespaces Files Functions Variables Typedefs Macros
Public Member Functions | Public Attributes | Protected Attributes | Friends | List of all members
algebra3d::Quaternion< fpType > Class Template Reference

A class to store quaternions. More...

#include <Quaternion.h>

Public Member Functions

 Quaternion ()
 
 Quaternion (const fpType(&data)[4])
 
 Quaternion (fpType x, fpType y, fpType z, fpType w)
 
 Quaternion (const Quaternion< fpType > &quat)
 
 Quaternion (const Vector3< fpType > &vec)
 
 Quaternion (Vector3< fpType > axis, fpType angle)
 
 Quaternion (const Matrix3< fpType > &mat)
 
virtual ~Quaternion ()
 
virtual void set (const fpType *data)
 
virtual void set (const Matrix3< fpType > &mat)
 
virtual void get (fpType *storage) const
 
virtual fpType getAngle () const
 
virtual Vector3< fpType > getAxis () const
 
virtual fpType getNorm () const
 
virtual void normalize ()
 
virtual bool isUnit () const
 
virtual Quaternion< fpType > getSqrtRotation () const
 
virtual Quaternion< fpType > getSqrtRotationTowards (const Quaternion< fpType > &quat) const
 
virtual void operator= (const Quaternion< fpType > &quat)
 
virtual const fpType & operator[] (int ind) const
 
virtual fpType & operator[] (int ind)
 
virtual bool compareRotations (const Quaternion< fpType > &quat, fpType precision=PRECISION) const
 
virtual bool compare (const Quaternion< fpType > &quat, const fpType &precision=PRECISION) const
 
virtual bool operator== (const Quaternion< fpType > &quat) const
 
virtual bool operator!= (const Quaternion< fpType > &quat) const
 
virtual Quaternion< fpType > inv () const
 
virtual void operator*= (const Quaternion< fpType > &quat)
 
virtual Quaternion< fpType > operator* (const Quaternion< fpType > &quat) const
 
virtual void scaleAngle (const fpType &mult)
 
virtual Quaternion< fpType > getScaledAngleRotation (const fpType &mult) const
 
virtual Vector3< fpType > operator* (const Vector3< fpType > &vec) const
 

Public Attributes

fpType & x
 
fpType & y
 
fpType & z
 
fpType & w
 

Protected Attributes

fpType data [4]
 

Friends

template<class fpT >
std::istream & operator>> (std::istream &stream, Quaternion< fpT > &quat)
 

Detailed Description

template<class fpType>
class algebra3d::Quaternion< fpType >

A class to store quaternions.

The main goal is to represent rotations, however the functionality is not limited to that.

Author
Jarek Glowacki

Constructor & Destructor Documentation

template<class fpType>
algebra3d::Quaternion< fpType >::Quaternion ( )

Creates an instance of a identity quaternion.

template<class fpType>
algebra3d::Quaternion< fpType >::Quaternion ( const fpType(&)  data[4])

Creates an instance using the provided data.

Parameters
[in]dataReference to the data to initialize the quaternion with.
template<class fpType>
algebra3d::Quaternion< fpType >::Quaternion ( fpType  x,
fpType  y,
fpType  z,
fpType  w 
)

Initializes the vector with the provided values.

Parameters
[in]xThe first element.
[in]yThe second element.
[in]zThe third element.
[in]wThe fourth element.
template<class fpType>
algebra3d::Quaternion< fpType >::Quaternion ( const Quaternion< fpType > &  quat)

Copies elements of the provided quaternion into this one.

Parameters
[in]quatThe quaternion to copy.
template<class fpType>
algebra3d::Quaternion< fpType >::Quaternion ( const Vector3< fpType > &  vec)

Copies the provided rotation represented by a Cayley vector.

Parameters
[in]vecThe Cayley vector to copy.
template<class fpType>
algebra3d::Quaternion< fpType >::Quaternion ( Vector3< fpType >  axis,
fpType  angle 
)

Creates a quaternion for the provided rotation given by axis and angle.

Parameters
[in]axisThe rotation axis (not necessary a unit vector).
[in]angleThe angle of rotation.
template<class fpType>
algebra3d::Quaternion< fpType >::Quaternion ( const Matrix3< fpType > &  mat)

Copies the provided rotation represented by a matrix.

Parameters
[in]matThe matrix to copy.
template<class fpType>
virtual algebra3d::Quaternion< fpType >::~Quaternion ( )
virtual

Does nothing. Virtual classes require virtual destructors.

Member Function Documentation

template<class fpType>
virtual bool algebra3d::Quaternion< fpType >::compare ( const Quaternion< fpType > &  quat,
const fpType &  precision = PRECISION 
) const
virtual

Checks if all elements of the provided quaternion are the same as in this one up to the provided precision. The comparison is simply checking if the difference between numbers is smaller or equal the precision.

Parameters
[in]quatThe quaternion to compare this with.
[in]precisionThe precision to use; by default the global PRECISION is used.
Returns
true if all entries are equal up to the precision, false otherwise.
template<class fpType>
virtual bool algebra3d::Quaternion< fpType >::compareRotations ( const Quaternion< fpType > &  quat,
fpType  precision = PRECISION 
) const
virtual

Checks if the rotation represented by this quaternion is identical with the one represented by the argument.

Parameters
[in]quatThe quaternion to compare this with.
[in]precisionThe precision to use; by default the global PRECISION is used.
Returns
true if the rotations are identical, false otherwise.
template<class fpType>
virtual void algebra3d::Quaternion< fpType >::get ( fpType *  storage) const
virtual

Copies the quaternion data to the provided array. First 4 positions from the given pointer are written).

Parameters
[out]storageThe array to copy the data to.
template<class fpType>
virtual fpType algebra3d::Quaternion< fpType >::getAngle ( ) const
virtual

Returns the angle of the rotation represented by this quaternion. If the quaternions is not a unit one the value is meaningless.

Returns
The angle of the rotation represented by this quaternion.
template<class fpType>
virtual Vector3<fpType> algebra3d::Quaternion< fpType >::getAxis ( ) const
virtual

Returns the axis of the rotation represented by this quaternion. If the quaternions is not a unit one the value is meaningless.

Returns
The axis of the rotation represented by this quaternion.
template<class fpType>
virtual fpType algebra3d::Quaternion< fpType >::getNorm ( ) const
virtual

Returns the L2 norm of the quaternion.

Returns
The L2 norm of the quaternion.
template<class fpType>
virtual Quaternion<fpType> algebra3d::Quaternion< fpType >::getScaledAngleRotation ( const fpType &  mult) const
virtual

Returns a quaternion representing a rotation around the same axis by an angle that is a given multiply of this rotation angle.

Parameters
multThe value to multiply the angle by.
template<class fpType>
virtual Quaternion<fpType> algebra3d::Quaternion< fpType >::getSqrtRotation ( ) const
virtual

Returns the quaternion representation of half of the rotation represented by this instance.

Returns
the quaternion representation of half of the rotation represented by this instance.
template<class fpType>
virtual Quaternion<fpType> algebra3d::Quaternion< fpType >::getSqrtRotationTowards ( const Quaternion< fpType > &  quat) const
virtual

Computes the rotation that is half the transition between this one and the provided one. That is to say that:

Quaternion q1, q2;
...
Quaternion trans = q1.getSqrtRotationTowards(q2);
// The following is true:
q1 * trans * trans == q2;

Returns it as a Quaternion.

Parameters
[in]quatThe other rotation.
Returns
the Quaternion that represents the square root of transition.
template<class fpType>
virtual Quaternion<fpType> algebra3d::Quaternion< fpType >::inv ( ) const
virtual

Returns a quaternion that represents inverse of this rotation, i.e. same angle, negative axis the axis of this rotation. For a non-unit quaternion may result in an error.

Returns
A quaternion that represents a rotation that is inverse of this one.
template<class fpType>
virtual bool algebra3d::Quaternion< fpType >::isUnit ( ) const
virtual

Returns true if this is a unit quaternion, false otherwise.

Returns
true if this is a unit quaternion, false otherwise.
template<class fpType>
virtual void algebra3d::Quaternion< fpType >::normalize ( )
virtual

Normalizes the quaternion (divides all elements by the norm).

template<class fpType>
virtual bool algebra3d::Quaternion< fpType >::operator!= ( const Quaternion< fpType > &  quat) const
virtual

Comparing operator. Checks if any element of this quaternion differs from respective element of the parameter.

Parameters
[in]quatThe quaternion vector to compare this with.
Returns
false if all entries are equal, true otherwise.
template<class fpType>
virtual Quaternion<fpType> algebra3d::Quaternion< fpType >::operator* ( const Quaternion< fpType > &  quat) const
virtual

Returns the product of this quaternion and the provided one.

Parameters
[in]quatThe matrix to multiply this vector.
Returns
The product of this quaternion and the provided one.
template<class fpType>
virtual Vector3<fpType> algebra3d::Quaternion< fpType >::operator* ( const Vector3< fpType > &  vec) const
virtual

Returns the effect of rotating the vector according to this quaternion. If this is not a unit quaternion this might result in an error.

Parameters
[in]vecThe vector to transform according to this quaternion.
Returns
The effect of rotating the vector according to this quaternion.
template<class fpType>
virtual void algebra3d::Quaternion< fpType >::operator*= ( const Quaternion< fpType > &  quat)
virtual

Post-multiplies this quaternion by the provided one.

Parameters
[in]quatThe quaternion to post-multiply this by.
template<class fpType>
virtual void algebra3d::Quaternion< fpType >::operator= ( const Quaternion< fpType > &  quat)
virtual

Copies elements of the provided quaternion into this one.

Parameters
[in]quatThe quaternion to copy.
template<class fpType>
virtual bool algebra3d::Quaternion< fpType >::operator== ( const Quaternion< fpType > &  quat) const
virtual

Checks if all elements of the provided quaternion are the same as this.

Parameters
[in]quatThe quaternion to compare this with.
Returns
true if all entries are equal, false otherwise.
template<class fpType>
virtual const fpType& algebra3d::Quaternion< fpType >::operator[] ( int  ind) const
virtual

Returns a reference to the element of the quaternion with the provided index. If the index is incorrect the closest correct one is used is returned. Version for constant instances.

Parameters
[in]indIndex of the element to return.
Returns
Reference to the selected element.
template<class fpType>
virtual fpType& algebra3d::Quaternion< fpType >::operator[] ( int  ind)
virtual

Returns a reference to the element of the quaternion with the provided index. If the index is incorrect the closest correct one is used is returned.

Parameters
[in]indIndex of the element to return.
Returns
Reference to the selected element.
template<class fpType>
virtual void algebra3d::Quaternion< fpType >::scaleAngle ( const fpType &  mult)
virtual

Changes the angle of rotation represented by this quaternion by multiplying it by the provided number.

Parameters
multThe value to multiply the angle by.
template<class fpType>
virtual void algebra3d::Quaternion< fpType >::set ( const fpType *  data)
virtual

Set the quaternion data to the values in the provided array. First 4 positions from the given pointer are read.

Parameters
[in]dataThe array with values to set.
template<class fpType>
virtual void algebra3d::Quaternion< fpType >::set ( const Matrix3< fpType > &  mat)
virtual

Set the quaternion data to represent the rotation given as a matrix.

Parameters
[in]matThe rotation matrix.

Member Data Documentation

template<class fpType>
fpType algebra3d::Quaternion< fpType >::data[4]
protected

The quaternion data.

template<class fpType>
fpType& algebra3d::Quaternion< fpType >::w

Reference to the fourth element of data.

template<class fpType>
fpType& algebra3d::Quaternion< fpType >::x

Reference to the first element of data.

template<class fpType>
fpType& algebra3d::Quaternion< fpType >::y

Reference to the second element of data.

template<class fpType>
fpType& algebra3d::Quaternion< fpType >::z

Reference to the third element of data.


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