Skip to content

Quaternion

Quaternion is the static container storing 4-component quaternion representing rotations in 3D space. It is used to store orientations and rotations due to deformation or other effects.

Constructors

cpp
Quaternion();

Default constructor. Initializes current quaternion to represent zero rotation ({1, 0, 0, 0}).

cpp
Quaternion(const Quaternion& rhS);

Copy constructor. Initializes current quaterion with the copy of rhs.

cpp
Quaternion(std::array<double,4> vecinit);

Constructs quaternion using array of four values.

Access operators

cpp
double& operator[](const size_t index);
double const& operator[](const size_t index) const;

Return (const) reference to the element index.

Arithmetic and vector operations

cpp
Quaternion operator+(const Quaternion rhS) const;

Returns sum of two quaternions.

cpp
Quaternion operator-(const Quaternion rhS) const;

Returns difference of two quaternions.

cpp
Quaternion operator*(const Quaternion rhS) const;

Returns a product of two quaternions.

cpp
Quaternion operator*(const double scalar) const;

Returns copy of the current quaternion with all elements multiplied by the factor scalar.

cpp
Quaternion operator/(const double divisor) const;
Returns copy of the current quaternion with all elements divided by the factor `divisor`.
cpp
Quaternion& operator+=(const Quaternion rhS);

Adds rhS to the current quaternion.

cpp
Quaternion& operator-=(const Quaternion rhS);

Subtracts rhS from the current quaternion.

cpp
Quaternion& operator*=(const Quaternion rhS);

Multiplies current quaternion by the rhS.

cpp
Quaternion& operator*=(const double scalar);

Multiplies current quaternion by the factor scalar.

cpp
Quaternion& operator/=(const double divisor);

Divides current quaternion by the factor scalar.

cpp
Quaternion& operator=(const Quaternion rhS);

Assigns the content of the rhS to the current container.

cpp
double length() const;

Returns length of the quaternion.

cpp
Quaternion& normalize();

Normalizes quaternion.

cpp
Quaternion normalized() const;

Returns normalized copy of the current quaternion.

cpp
Quaternion& conjugate();

Conjugates quaternion (reverse rotation).

cpp
Quaternion conjugated() const;

Returns conjugated copy of the current quaternion (reverse rotation).

cpp
Quaternion& invert();

Inverts current quaternion (reverse rotation if quaternion is normalized).

cpp
Quaternion inverted() const;

Returns inverted copy of the current quaternion (reverse rotation if quaternion is normalized).

cpp
void setRotationMatrix(void);

Sets internally stored rotation matrix representing the same rotation at the current quaternion.

cpp
dMatrix3x3 getRotationMatrix(const bool Active = true);

Returns rotation matrix representing the same rotation at the current quaternion (default: active rotation). Allows switching between active and passive rotation.

cpp
static Quaternion lerp(const Quaternion& rhSQ1, const Quaternion& rhSQ2, const double t);

Returns linear interpolation between two quaternions, where 0.0 < t < 1.0.

cpp
static Quaternion slerp(const Quaternion& a, const Quaternion& b, const double t);

Returns spherical linear interpolation between two quaternions, where 0.0 < t < 1.0.

Data manipulation methods

cpp
void set(const double sIn, const double x, const double y, const double z);

Sets quaternion using individual entries.

cpp
void set(const double sIn, const dVector3 vIn);

Sets quaternion using first entry and imaginary part vector.

cpp
void set(const dMatrix3x3& RotMatrix);

Sets quaternion from rotation matrix RotMatrix.

cpp
void set_entry(const int idx, const double val);

Sets individual entry.

cpp
void set(dVector3 Axis, const double Angle);

Sets quaternion from rotation axis and angle.

cpp
void set_to_zero();

Sets zero rotation quaternion ({1, 0, 0, 0}).

Container properties

cpp
constexpr size_t size(void) const;

Returns the size of the quaternion.

MPI communication methods

cpp
void pack(std::vector<double>& buffer);

Packs the content of the current object into the MPI communication buffer.

cpp
void unpack(std::vector<double>& buffer, size_t& it);

Unpacks (reads) the content of the current object from the MPI communication buffer. The existing data in the container is overwritten.

Read/write methods

cpp
std::string print(void) const;

Returns formatted string of the quaternion values ready to print to the terminal.

cpp
void read_ASCII(std::istream& inp);

Reads quaternion content from the input stream.

cpp
void write_ASCII(std::ostream& outp, const int precision = 16, const char sep = ' ') const;

Writes quaternion content in ASCII format with the specified precision using sep as entry separator into the output stream.

cpp
std::string get_output_string(const int precision = 16, const char sep = ' ') const;

Returns output string with quaternion content in ASCII format with the specified precision using sep as entry separator.

cpp
std::vector<double> get_vector() const;

Returns std::vector containing current quaternion components.

cpp
std::vector<float> get_vector_float() const;

Returns std::vector<float> containing current quaternion components rounded to float precision.

Released under the GNU GPLv3 License.