Class Quaternion

Class Documentation

class Quaternion

This class represents a Quaternion.

The Unit Quaternion is one possible representation of the attitude of an object in tree-dimensional space.

This Quaternion class is implemented according to Diebel, James. Representing Attitude: Euler Angle, Unit Quaternions, and Rotation Vectors. Stanford University. 2006. - Technical Report.

Public Functions

inline Quaternion()

Default constructor.

Constructs the (1,0,0,0) Unit Quaternion representing the identity rotation.

Quaternion(const Quaternion &other)

Copy constructor.

Quaternion(float u, float x, float y, float z)

Constructor.

Constructs a Quaternion from four single values

Quaternion(const Vector3 &other)

Constructor.

Parameters:

other – a vector containing euler angles

Quaternion(double roll, double pitch, double yaw)

Constructor from Euler angles.

Constructs a Unit Quaternion from Euler angles / Tait Bryan angles (in radians) according to the 1-2-3 convention.

Parameters:
  • roll – phi/roll angle (rotation about x-axis)

  • pitch – theta/pitch angle (rotation about y-axis)

  • yaw – psi/yaw angle (rotation about z-axis)

Quaternion(const Vector3 &axis, double angle)

Constructs a Unit Quaternion from a rotation angle and axis.

Vector3 toEuler() const

Conversion to Euler angles.

Converts the attitude represented by this to Euler angles (roll, pitch, yaw).

void toRotMatrix(std::vector<double> &rot_matrix_3_3) const
inline const float &operator()(unsigned int i) const
inline float &operator()(unsigned int i)
float norm() const
Quaternion normalized() const
Quaternion &normalize()
void operator/=(float x)
Quaternion &operator=(const Quaternion &other)
bool operator==(const Quaternion &other) const
Quaternion operator*(const Quaternion &other) const

Quaternion multiplication.

Standard Quaternion multiplication which is not commutative.

Returns:

this * other

Quaternion operator*(const Vector3 &v) const

Quaternion multiplication with extended vector.

Returns:

q * (0, v)

inline Quaternion inv() const

Inversion.

Returns:

A copy of this Quaterion inverted

Quaternion &inv_IP()

Inversion.

Inverts this Quaternion

Returns:

a reference to this Quaternion

Vector3 rotate(const Vector3 &v) const

Rotate a vector.

Rotates a vector to the body fixed coordinate system according to the attitude represented by this Quaternion.

Parameters:

v – a vector represented in world coordinates

Returns:

v represented in body-fixed coordinates

inline float &u()
inline float &x()
inline float &y()
inline float &z()
inline const float &u() const
inline const float &x() const
inline const float &y() const
inline const float &z() const
std::istream &read(std::istream &s)
std::ostream &write(std::ostream &s) const
std::istream &readBinary(std::istream &s)
std::ostream &writeBinary(std::ostream &s) const

Protected Attributes

float data[4]

Friends

friend Quaternion operator*(const Vector3 &v, const Quaternion &q)

Quaternion multiplication with extended vector.

Returns:

(0, v) * q