Algebra3D
Algebra for 3D transformations
|
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) |
A class to store quaternions.
The main goal is to represent rotations, however the functionality is not limited to that.
algebra3d::Quaternion< fpType >::Quaternion | ( | ) |
Creates an instance of a identity quaternion.
algebra3d::Quaternion< fpType >::Quaternion | ( | const fpType(&) | data[4] | ) |
Creates an instance using the provided data.
[in] | data | Reference to the data to initialize the quaternion with. |
algebra3d::Quaternion< fpType >::Quaternion | ( | fpType | x, |
fpType | y, | ||
fpType | z, | ||
fpType | w | ||
) |
Initializes the vector with the provided values.
[in] | x | The first element. |
[in] | y | The second element. |
[in] | z | The third element. |
[in] | w | The fourth element. |
algebra3d::Quaternion< fpType >::Quaternion | ( | const Quaternion< fpType > & | quat | ) |
Copies elements of the provided quaternion into this one.
[in] | quat | The quaternion to copy. |
algebra3d::Quaternion< fpType >::Quaternion | ( | const Vector3< fpType > & | vec | ) |
Copies the provided rotation represented by a Cayley vector.
[in] | vec | The Cayley vector to copy. |
algebra3d::Quaternion< fpType >::Quaternion | ( | Vector3< fpType > | axis, |
fpType | angle | ||
) |
Creates a quaternion for the provided rotation given by axis and angle.
[in] | axis | The rotation axis (not necessary a unit vector). |
[in] | angle | The angle of rotation. |
algebra3d::Quaternion< fpType >::Quaternion | ( | const Matrix3< fpType > & | mat | ) |
Copies the provided rotation represented by a matrix.
[in] | mat | The matrix to copy. |
|
virtual |
Does nothing. Virtual classes require virtual destructors.
|
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.
[in] | quat | The quaternion to compare this with. |
[in] | precision | The precision to use; by default the global PRECISION is used. |
true
if all entries are equal up to the precision, false
otherwise.
|
virtual |
Checks if the rotation represented by this quaternion is identical with the one represented by the argument.
[in] | quat | The quaternion to compare this with. |
[in] | precision | The precision to use; by default the global PRECISION is used. |
true
if the rotations are identical, false
otherwise.
|
virtual |
Copies the quaternion data to the provided array. First 4 positions from the given pointer are written).
[out] | storage | The array to copy the data to. |
|
virtual |
Returns the angle of the rotation represented by this quaternion. If the quaternions is not a unit one the value is meaningless.
|
virtual |
Returns the axis of the rotation represented by this quaternion. If the quaternions is not a unit one the value is meaningless.
|
virtual |
Returns the L2 norm of the quaternion.
|
virtual |
Returns a quaternion representing a rotation around the same axis by an angle that is a given multiply of this rotation angle.
mult | The value to multiply the angle by. |
|
virtual |
Returns the quaternion representation of half of the rotation represented by this instance.
|
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.
[in] | quat | The other rotation. |
|
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.
|
virtual |
Returns true
if this is a unit quaternion, false
otherwise.
true
if this is a unit quaternion, false
otherwise.
|
virtual |
Normalizes the quaternion (divides all elements by the norm).
|
virtual |
Comparing operator. Checks if any element of this quaternion differs from respective element of the parameter.
[in] | quat | The quaternion vector to compare this with. |
false
if all entries are equal, true
otherwise.
|
virtual |
Returns the product of this quaternion and the provided one.
[in] | quat | The matrix to multiply this vector. |
|
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.
[in] | vec | The vector to transform according to this quaternion. |
|
virtual |
Post-multiplies this quaternion by the provided one.
[in] | quat | The quaternion to post-multiply this by. |
|
virtual |
Copies elements of the provided quaternion into this one.
[in] | quat | The quaternion to copy. |
|
virtual |
Checks if all elements of the provided quaternion are the same as this.
[in] | quat | The quaternion to compare this with. |
true
if all entries are equal, false
otherwise.
|
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.
[in] | ind | Index of the element to return. |
|
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.
[in] | ind | Index of the element to return. |
|
virtual |
Changes the angle of rotation represented by this quaternion by multiplying it by the provided number.
mult | The value to multiply the angle by. |
|
virtual |
Set the quaternion data to the values in the provided array. First 4 positions from the given pointer are read.
[in] | data | The array with values to set. |
|
virtual |
Set the quaternion data to represent the rotation given as a matrix.
[in] | mat | The rotation matrix. |
|
protected |
The quaternion data.
fpType& algebra3d::Quaternion< fpType >::w |
Reference to the fourth element of data.
fpType& algebra3d::Quaternion< fpType >::x |
Reference to the first element of data.
fpType& algebra3d::Quaternion< fpType >::y |
Reference to the second element of data.
fpType& algebra3d::Quaternion< fpType >::z |
Reference to the third element of data.