The Quaternion class defined in C++ provides a quaternion representation for attitude in Cartesian coordinate systems. It is derived from the CartesianVector class and includes additional functionalities specific to attitude representation.

The Quaternion Class

Description and Naming

The Quaternion class is a templated class with one template argument - T. Quaternion<T> produces a quaternion with four elements of type T. The argument is:

  • T - The type of the quaternion elements. This should be a floating point type.

The Quaternion class inherits from the CartesianVector class but has additional characteristics:

  • It always has four elements.

  • The default constructor initializes it to represent zero rotation (1, 0, 0, 0).

  • It includes functions to convert to other attitude representations and calculate the rate of change based on angular velocity.

For a complete guide on interacting with the Quaternion class, refer to the Doxygen documentation: Quaternion Doxygen

Creating a Quaternion

Description C++ Example Python Example

Default Constructor - Creates a quaternion representing zero rotation.

Quaternion<double> quat1;
quat1 = Quaternion()

Constructor with Initial Value - Creates a quaternion initialized with values from an initializer list.

Quaternion<double> quat2({1, 0, 0, 0});
quat2 = Quaternion([1, 0, 0, 0])

Constructor with std::array - Creates a quaternion initialized with values from a std::array.

std::array<double, 4> initial = {1, 0, 0, 0};
Quaternion<double> quat3(initial);
initial = [1, 0, 0, 0]
quat3 = Quaternion(initial)

Copy Constructor - Creates a new quaternion as a copy of another quaternion.

Quaternion<double> quat4(quat3);
quat4 = quat3

Assignment Operator - Assigns values from one quaternion to another.

Quaternion<double> quat5 = quat4;
quat5 = quat4

Calculating the Rate of Change

Description C++ Example Python Example

Rate of Change - Calculates the rate of change of the quaternion based on the angular velocity vector.

CartesianVector<double, 3> omega;
Matrix<double, 4, 1> quatdot;
quat1.rate(omega, quatdot);
omega = CartesianVector3D()
quatdot = Matrix41()
quat1.rate(omega, quatdot)

Conversions to Other Attitude Representations

Description C++ Example Python Example

Convert to DCM - Converts the quaternion to a Direction Cosine Matrix (DCM).

DCM<double> dcm;
quat1.toDCM(dcm);
dcm = DCM()
quat1.toDCM(dcm)

Convert to DCM (Return by Value) - Converts and returns the quaternion as a DCM.

DCM<double> dcm = quat1.toDCM();
dcm = quat1.toDCM()

Convert to MRP - Converts the quaternion to a Modified Rodrigues Parameter (MRP).

MRP<double> mrp;
quat1.toMRP(mrp);
mrp = MRP()
quat1.toMRP(mrp)

Convert to MRP (Return by Value) - Converts and returns the quaternion as a MRP.

MRP<double> mrp = quat1.toMRP();
mrp = quat1.toMRP()