38 constexpr Quaternion(
double w,
double x,
double y,
double z)
39 : m_w{w}, m_x{x}, m_y{y}, m_z{z} {}
47 return Quaternion{m_w + other.m_w, m_x + other.m_x, m_y + other.m_y,
57 return Quaternion{m_w - other.m_w, m_x - other.m_x, m_y - other.m_y,
67 return Quaternion{m_w * other, m_x * other, m_y * other, m_z * other};
76 return Quaternion{m_w / other, m_x / other, m_y / other, m_z / other};
87 const auto& r2 = other.m_w;
90 double dot = m_x * other.m_x + m_y * other.m_y + m_z * other.m_z;
93 double cross_x = m_y * other.m_z - other.m_y * m_z;
94 double cross_y = other.m_x * m_z - m_x * other.m_z;
95 double cross_z = m_x * other.m_y - other.m_x * m_y;
100 r1 * other.m_x + r2 * m_x + cross_x,
101 r1 * other.m_y + r2 * m_y + cross_y,
102 r1 * other.m_z + r2 * m_z + cross_z};
120 return W() * other.
W() +
X() * other.
X() +
Y() * other.
Y() +
135 double norm =
Norm();
143 double norm =
Norm();
174 double axial_magnitude =
gcem::hypot(m_x, m_y, m_z);
175 double cosine =
gcem::cos(axial_magnitude);
179 if (axial_magnitude < 1e-9) {
181 double axial_magnitude_sq = axial_magnitude * axial_magnitude;
182 double axial_magnitude_sq_sq = axial_magnitude_sq * axial_magnitude_sq;
184 1.0 - axial_magnitude_sq / 6.0 + axial_magnitude_sq_sq / 120.0;
186 axial_scalar =
gcem::sin(axial_magnitude) / axial_magnitude;
189 return Quaternion(cosine * scalar,
X() * axial_scalar * scalar,
190 Y() * axial_scalar * scalar,
Z() * axial_scalar * scalar);
202 double norm =
Norm();
207 double s_norm =
W() / norm;
210 return Quaternion{scalar, -std::numbers::pi, 0, 0};
219 v_scalar = 1.0 /
W() - 1.0 / 3.0 * v_norm * v_norm / (
W() *
W() *
W());
224 return Quaternion{scalar, v_scalar * m_x, v_scalar * m_y, v_scalar * m_z};
230 constexpr double W()
const {
return m_w; }
235 constexpr double X()
const {
return m_x; }
240 constexpr double Y()
const {
return m_y; }
245 constexpr double Z()
const {
return m_z; }
262 scalar = (2.0 /
W() - 2.0 / 3.0 * norm * norm / (
W() *
W() *
W()));
271 return Eigen::Vector3d{{scalar * m_x, scalar * m_y, scalar * m_z}};
288 double theta =
gcem::hypot(rvec(0), rvec(1), rvec(2));
296 axial_scalar = 1.0 / 2.0 - theta * theta / 48.0;
298 axial_scalar =
gcem::sin(theta / 2) / theta;
301 return Quaternion{cos, axial_scalar * rvec(0), axial_scalar * rvec(1),
302 axial_scalar * rvec(2)};
#define WPILIB_DLLEXPORT
Definition SymbolExports.hpp:36
Represents a quaternion.
Definition Quaternion.hpp:23
constexpr double W() const
Returns W component of the quaternion.
Definition Quaternion.hpp:230
constexpr Quaternion Inverse() const
Returns the inverse of the quaternion.
Definition Quaternion.hpp:134
constexpr Quaternion operator-(const Quaternion &other) const
Subtracts another quaternion.
Definition Quaternion.hpp:56
constexpr Quaternion operator/(double other) const
Divides by a scalar value.
Definition Quaternion.hpp:75
constexpr double Dot(const Quaternion &other) const
Returns the elementwise product of two quaternions.
Definition Quaternion.hpp:119
constexpr Quaternion operator+(const Quaternion &other) const
Adds with another quaternion.
Definition Quaternion.hpp:46
constexpr Quaternion Normalize() const
Normalizes the quaternion.
Definition Quaternion.hpp:142
constexpr Quaternion(double w, double x, double y, double z)
Constructs a quaternion with the given components.
Definition Quaternion.hpp:38
constexpr Quaternion Exp() const
Matrix exponential of a quaternion.
Definition Quaternion.hpp:171
constexpr Quaternion operator*(const Quaternion &other) const
Multiply with another quaternion.
Definition Quaternion.hpp:84
constexpr bool operator==(const Quaternion &other) const
Checks equality between this Quaternion and another object.
Definition Quaternion.hpp:111
constexpr double X() const
Returns X component of the quaternion.
Definition Quaternion.hpp:235
constexpr Eigen::Vector3d ToRotationVector() const
Returns the rotation vector representation of this quaternion.
Definition Quaternion.hpp:252
constexpr double Z() const
Returns Z component of the quaternion.
Definition Quaternion.hpp:245
constexpr Quaternion Pow(double t) const
Calculates this quaternion raised to a power.
Definition Quaternion.hpp:161
constexpr Quaternion Log() const
Log operator of a quaternion.
Definition Quaternion.hpp:201
constexpr Quaternion()=default
Constructs a quaternion with a default angle of 0 degrees.
static constexpr Quaternion FromRotationVector(const Eigen::Vector3d &rvec)
Returns the quaternion representation of this rotation vector.
Definition Quaternion.hpp:281
constexpr Quaternion Conjugate() const
Returns the conjugate of the quaternion.
Definition Quaternion.hpp:127
constexpr Quaternion operator*(double other) const
Multiples with a scalar value.
Definition Quaternion.hpp:66
constexpr double Y() const
Returns Y component of the quaternion.
Definition Quaternion.hpp:240
constexpr double Norm() const
Calculates the L2 norm of the quaternion.
Definition Quaternion.hpp:154
constexpr T abs(const T x) noexcept
Compile-time absolute value function.
Definition abs.hpp:40
constexpr return_t< T > log(const T x) noexcept
Compile-time natural logarithm function.
Definition log.hpp:186
constexpr return_t< T > cos(const T x) noexcept
Compile-time cosine function.
Definition cos.hpp:83
constexpr return_t< T > sin(const T x) noexcept
Compile-time sine function.
Definition sin.hpp:85
constexpr common_return_t< T1, T2 > hypot(const T1 x, const T2 y) noexcept
Compile-time Pythagorean addition function.
Definition hypot.hpp:147
constexpr return_t< T > sqrt(const T x) noexcept
Compile-time square-root function.
Definition sqrt.hpp:109
constexpr return_t< T > exp(const T x) noexcept
Compile-time exponential function.
Definition exp.hpp:130
constexpr common_return_t< T1, T2 > atan2(const T1 y, const T2 x) noexcept
Compile-time two-argument arctangent function.
Definition atan2.hpp:88
Definition LinearSystem.hpp:20
WPILIB_DLLEXPORT void to_json(wpi::util::json &json, const Translation2d &state)
WPILIB_DLLEXPORT void from_json(const wpi::util::json &json, Translation2d &state)
Definition raw_os_ostream.hpp:19