35 constexpr Quaternion(
double w,
double x,
double y,
double z)
36 : m_w{w}, m_x{x}, m_y{y}, m_z{z} {}
44 return Quaternion{m_w + other.m_w, m_x + other.m_x, m_y + other.m_y,
54 return Quaternion{m_w - other.m_w, m_x - other.m_x, m_y - other.m_y,
64 return Quaternion{m_w * other, m_x * other, m_y * other, m_z * other};
73 return Quaternion{m_w / other, m_x / other, m_y / other, m_z / other};
84 const auto& r2 = other.m_w;
87 double dot = m_x * other.m_x + m_y * other.m_y + m_z * other.m_z;
90 double cross_x = m_y * other.m_z - other.m_y * m_z;
91 double cross_y = other.m_x * m_z - m_x * other.m_z;
92 double cross_z = m_x * other.m_y - other.m_x * m_y;
97 r1 * other.m_x + r2 * m_x + cross_x,
98 r1 * other.m_y + r2 * m_y + cross_y,
99 r1 * other.m_z + r2 * m_z + cross_z};
117 return W() * other.
W() +
X() * other.
X() +
Y() * other.
Y() +
132 double norm =
Norm();
140 double norm =
Norm();
171 double axial_magnitude =
gcem::hypot(m_x, m_y, m_z);
172 double cosine =
gcem::cos(axial_magnitude);
176 if (axial_magnitude < 1e-9) {
178 double axial_magnitude_sq = axial_magnitude * axial_magnitude;
179 double axial_magnitude_sq_sq = axial_magnitude_sq * axial_magnitude_sq;
181 1.0 - axial_magnitude_sq / 6.0 + axial_magnitude_sq_sq / 120.0;
183 axial_scalar =
gcem::sin(axial_magnitude) / axial_magnitude;
186 return Quaternion(cosine * scalar,
X() * axial_scalar * scalar,
187 Y() * axial_scalar * scalar,
Z() * axial_scalar * scalar);
199 double norm =
Norm();
204 double s_norm =
W() / norm;
207 return Quaternion{scalar, -std::numbers::pi, 0, 0};
216 v_scalar = 1.0 /
W() - 1.0 / 3.0 * v_norm * v_norm / (
W() *
W() *
W());
221 return Quaternion{scalar, v_scalar * m_x, v_scalar * m_y, v_scalar * m_z};
227 constexpr double W()
const {
return m_w; }
232 constexpr double X()
const {
return m_x; }
237 constexpr double Y()
const {
return m_y; }
242 constexpr double Z()
const {
return m_z; }
259 scalar = (2.0 /
W() - 2.0 / 3.0 * norm * norm / (
W() *
W() *
W()));
268 return Eigen::Vector3d{{scalar * m_x, scalar * m_y, scalar * m_z}};
285 double theta =
gcem::hypot(rvec(0), rvec(1), rvec(2));
293 axial_scalar = 1.0 / 2.0 - theta * theta / 48.0;
295 axial_scalar =
gcem::sin(theta / 2) / theta;
298 return Quaternion{cos, axial_scalar * rvec(0), axial_scalar * rvec(1),
299 axial_scalar * rvec(2)};
#define WPILIB_DLLEXPORT
Definition SymbolExports.hpp:36
Represents a quaternion.
Definition Quaternion.hpp:20
constexpr double W() const
Returns W component of the quaternion.
Definition Quaternion.hpp:227
constexpr Quaternion Inverse() const
Returns the inverse of the quaternion.
Definition Quaternion.hpp:131
constexpr Quaternion operator-(const Quaternion &other) const
Subtracts another quaternion.
Definition Quaternion.hpp:53
constexpr Quaternion operator/(double other) const
Divides by a scalar value.
Definition Quaternion.hpp:72
constexpr double Dot(const Quaternion &other) const
Returns the elementwise product of two quaternions.
Definition Quaternion.hpp:116
constexpr Quaternion operator+(const Quaternion &other) const
Adds with another quaternion.
Definition Quaternion.hpp:43
constexpr Quaternion Normalize() const
Normalizes the quaternion.
Definition Quaternion.hpp:139
constexpr Quaternion(double w, double x, double y, double z)
Constructs a quaternion with the given components.
Definition Quaternion.hpp:35
constexpr Quaternion Exp() const
Matrix exponential of a quaternion.
Definition Quaternion.hpp:168
constexpr Quaternion operator*(const Quaternion &other) const
Multiply with another quaternion.
Definition Quaternion.hpp:81
constexpr bool operator==(const Quaternion &other) const
Checks equality between this Quaternion and another object.
Definition Quaternion.hpp:108
constexpr double X() const
Returns X component of the quaternion.
Definition Quaternion.hpp:232
constexpr Eigen::Vector3d ToRotationVector() const
Returns the rotation vector representation of this quaternion.
Definition Quaternion.hpp:249
constexpr double Z() const
Returns Z component of the quaternion.
Definition Quaternion.hpp:242
constexpr Quaternion Pow(double t) const
Calculates this quaternion raised to a power.
Definition Quaternion.hpp:158
constexpr Quaternion Log() const
Log operator of a quaternion.
Definition Quaternion.hpp:198
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:278
constexpr Quaternion Conjugate() const
Returns the conjugate of the quaternion.
Definition Quaternion.hpp:124
constexpr Quaternion operator*(double other) const
Multiples with a scalar value.
Definition Quaternion.hpp:63
constexpr double Y() const
Returns Y component of the quaternion.
Definition Quaternion.hpp:237
constexpr double Norm() const
Calculates the L2 norm of the quaternion.
Definition Quaternion.hpp:151
basic_json<> json
default specialization
Definition json_fwd.hpp:62
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)