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
cppQuaternion();Default constructor. Initializes current quaternion to represent zero rotation (
{1, 0, 0, 0}).
cppQuaternion(const Quaternion& rhS);Copy constructor. Initializes current quaterion with the copy of
rhs.
cppQuaternion(std::array<double,4> vecinit);Constructs quaternion using array of four values.
Access operators
cppdouble& operator[](const size_t index); double const& operator[](const size_t index) const;Return (const) reference to the element
index.
Arithmetic and vector operations
cppQuaternion operator+(const Quaternion rhS) const;Returns sum of two quaternions.
cppQuaternion operator-(const Quaternion rhS) const;Returns difference of two quaternions.
cppQuaternion operator*(const Quaternion rhS) const;Returns a product of two quaternions.
cppQuaternion operator*(const double scalar) const;Returns copy of the current quaternion with all elements multiplied by the factor
scalar.
cppQuaternion operator/(const double divisor) const; Returns copy of the current quaternion with all elements divided by the factor `divisor`.
cppQuaternion& operator+=(const Quaternion rhS);Adds
rhSto the current quaternion.
cppQuaternion& operator-=(const Quaternion rhS);Subtracts
rhSfrom the current quaternion.
cppQuaternion& operator*=(const Quaternion rhS);Multiplies current quaternion by the
rhS.
cppQuaternion& operator*=(const double scalar);Multiplies current quaternion by the factor
scalar.
cppQuaternion& operator/=(const double divisor);Divides current quaternion by the factor
scalar.
cppQuaternion& operator=(const Quaternion rhS);Assigns the content of the
rhSto the current container.
cppdouble length() const;Returns length of the quaternion.
cppQuaternion& normalize();Normalizes quaternion.
cppQuaternion normalized() const;Returns normalized copy of the current quaternion.
cppQuaternion& conjugate();Conjugates quaternion (reverse rotation).
cppQuaternion conjugated() const;Returns conjugated copy of the current quaternion (reverse rotation).
cppQuaternion& invert();Inverts current quaternion (reverse rotation if quaternion is normalized).
cppQuaternion inverted() const;Returns inverted copy of the current quaternion (reverse rotation if quaternion is normalized).
cppvoid setRotationMatrix(void);Sets internally stored rotation matrix representing the same rotation at the current quaternion.
cppdMatrix3x3 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.
cppstatic Quaternion lerp(const Quaternion& rhSQ1, const Quaternion& rhSQ2, const double t);Returns linear interpolation between two quaternions, where 0.0 < t < 1.0.
cppstatic 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
cppvoid set(const double sIn, const double x, const double y, const double z);Sets quaternion using individual entries.
cppvoid set(const double sIn, const dVector3 vIn);Sets quaternion using first entry and imaginary part vector.
cppvoid set(const dMatrix3x3& RotMatrix);Sets quaternion from rotation matrix
RotMatrix.
cppvoid set_entry(const int idx, const double val);Sets individual entry.
cppvoid set(dVector3 Axis, const double Angle);Sets quaternion from rotation axis and angle.
cppvoid set_to_zero();Sets zero rotation quaternion (
{1, 0, 0, 0}).
Container properties
cppconstexpr size_t size(void) const;Returns the size of the quaternion.
MPI communication methods
cppvoid pack(std::vector<double>& buffer);Packs the content of the current object into the MPI communication buffer.
cppvoid 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
cppstd::string print(void) const;Returns formatted string of the quaternion values ready to print to the terminal.
cppvoid read_ASCII(std::istream& inp);Reads quaternion content from the input stream.
cppvoid write_ASCII(std::ostream& outp, const int precision = 16, const char sep = ' ') const;Writes quaternion content in ASCII format with the specified
precisionusingsepas entry separator into the output stream.
cppstd::string get_output_string(const int precision = 16, const char sep = ' ') const;Returns output string with quaternion content in ASCII format with the specified
precisionusingsepas entry separator.
cppstd::vector<double> get_vector() const;Returns
std::vectorcontaining current quaternion components.
cppstd::vector<float> get_vector_float() const;Returns
std::vector<float>containing current quaternion components rounded tofloatprecision.