7 #ifndef INCLUDE_IMUNANO33_QUATERNION_HPP_
8 #define INCLUDE_IMUNANO33_QUATERNION_HPP_
10 #ifdef IMUNANO33_EMBED
16 #ifdef IMUNANO33_EMBED
24 #ifdef IMUNANO33_EMBED
58 if (
w == 0 && isZero(
vec)) {
75 m_vec = normalize(
vec) * sin(ang / 2);
134 const num_t newW = conju.
w() / (mag * mag);
148 return sqrt(m_w * m_w + x(m_vec) * x(m_vec) + y(m_vec) * y(m_vec) +
149 z(m_vec) * z(m_vec));
163 const num_t newW = m_w / mag;
164 const Vector3D newVec = m_vec / mag;
188 #ifdef IMUNANO33_EMBED
201 return Quaternion{wl * wr - dot(vl, vr), vr * wl + vl * wr + cross(vl, vr)};
213 return lhs.
w() == rhs.
w() && lhs.
vec() == rhs.
vec();
225 return !(lhs == rhs);
bool operator==(const Quaternion &lhs, const Quaternion &rhs)
Equality of two quaternions.
Definition: quaternion.hpp:212
bool operator!=(const Quaternion &lhs, const Quaternion &rhs)
Inequality of two quaternions.
Definition: quaternion.hpp:224
Quaternion operator*(const Quaternion &lhs, const Quaternion &rhs)
Product of two quaternions.
Definition: quaternion.hpp:187
A minimized version of vectors for embedded devices without access to the STL (such as on an Arduino,...
Contains imunano33::TempUnit and imunano33::PressureUnit enums, in addition to number type.
double num_t
Alias to number type depending on embed.
Definition: unit.hpp:34
A simple quaternion class for rotations.
Definition: quaternion.hpp:40
Quaternion unit() const
Gets equivalent unit quaternion.
Definition: quaternion.hpp:161
Quaternion inv() const
Gets quaternion inverse.
Definition: quaternion.hpp:131
Quaternion(const Vector3D &vec, const num_t ang)
Constructor for a rotation quaternion.
Definition: quaternion.hpp:73
Quaternion(const num_t w, const Vector3D &vec)
Constructor for a basic quaternion.
Definition: quaternion.hpp:55
Quaternion conj() const
Gets the quaternion conjugate.
Definition: quaternion.hpp:124
Vector3D rotate(const Vector3D &vec) const
Rotates a vector with current quaternion object.
Definition: quaternion.hpp:268
Quaternion & operator=(const Quaternion &other)=default
Assignment operator.
num_t norm() const
Gets quaternion norm.
Definition: quaternion.hpp:147
Quaternion(const Quaternion &other)=default
Copy constructor.
Quaternion()
Default constructor.
Definition: quaternion.hpp:47
Vector3D vec() const
Gets the vector component of the quaternion.
Definition: quaternion.hpp:117
Quaternion(Quaternion &&)=default
Move constructor.
num_t w() const
Gets the scalar component of the quaternion.
Definition: quaternion.hpp:110
Quaternion & operator*=(const Quaternion &other)
Multiplies a quaternion in place.
Definition: quaternion.hpp:253
Quaternion & operator=(Quaternion &&)=default
Move assignment.
~Quaternion()=default
Destructor.
A simple 3D vector representation.
Definition: simplevectors.hpp:844
A minimal 3D vector representation.
Definition: sv_embed.hpp:168