39 : m_cos{
gcem::cos(value.template convert<
units::radian>().value())},
40 m_sin{
gcem::sin(value.template convert<
units::radian>().value())} {}
51 if (magnitude > 1e-6) {
52 m_cos = x / magnitude;
53 m_sin = y / magnitude;
57 if (!std::is_constant_evaluated()) {
59 "x and y components of Rotation2d are zero\n{}",
71 constexpr explicit Rotation2d(
const Eigen::Matrix2d& rotationMatrix) {
73 []<
typename Matrix2d>(
const Matrix2d& R) -> std::pair<double, double> {
76 if ((R * R.transpose() - Matrix2d::Identity()).norm() > 1e-9) {
77 throw std::domain_error(
"Rotation matrix isn't orthogonal");
84 throw std::domain_error(
85 "Rotation matrix is orthogonal but not special orthogonal");
90 return {R(0, 0), R(1, 0)};
93 if (std::is_constant_evaluated()) {
95 m_cos = std::get<0>(cossin);
96 m_sin = std::get<1>(cossin);
98 auto cossin = impl(rotationMatrix);
99 m_cos = std::get<0>(cossin);
100 m_sin = std::get<1>(cossin);
116 return RotateBy(other);
131 return *
this + -other;
161 return *
this * (1.0 /
scalar);
171 return gcem::hypot(Cos() - other.Cos(), Sin() - other.Sin()) < 1E-9;
188 return {Cos() * other.Cos() - Sin() * other.Sin(),
189 Cos() * other.Sin() + Sin() * other.Cos()};
198 return Eigen::Matrix2d{{m_cos, -m_sin}, {m_sin, m_cos}};
215 constexpr units::degree_t
Degrees()
const {
return Radians(); }
222 constexpr double Cos()
const {
return m_cos; }
229 constexpr double Sin()
const {
return m_sin; }
236 constexpr double Tan()
const {
return Sin() / Cos(); }
#define WPILIB_DLLEXPORT
Definition SymbolExports.h:36
namespace for Niels Lohmann
Definition json.h:99
A rotation in a 2D coordinate frame represented by a point on the unit circle (cosine and sine).
Definition Rotation2d.h:26
constexpr Rotation2d operator/(double scalar) const
Divides the current rotation by a scalar.
Definition Rotation2d.h:160
constexpr Rotation2d(units::angle_unit auto value)
Constructs a Rotation2d with the given angle.
Definition Rotation2d.h:38
constexpr Rotation2d operator-() const
Takes the inverse of the current rotation.
Definition Rotation2d.h:140
constexpr Rotation2d operator-(const Rotation2d &other) const
Subtracts the new rotation from the current rotation and returns the new rotation.
Definition Rotation2d.h:130
constexpr bool operator==(const Rotation2d &other) const
Checks equality between this Rotation2d and another object.
Definition Rotation2d.h:170
constexpr double Tan() const
Returns the tangent of the rotation.
Definition Rotation2d.h:236
constexpr Rotation2d RotateBy(const Rotation2d &other) const
Adds the new rotation to the current rotation using a rotation matrix.
Definition Rotation2d.h:187
constexpr Rotation2d(const Eigen::Matrix2d &rotationMatrix)
Constructs a Rotation2d from a rotation matrix.
Definition Rotation2d.h:71
constexpr units::degree_t Degrees() const
Returns the degree value of the rotation constrained within [-180, 180].
Definition Rotation2d.h:215
constexpr Eigen::Matrix2d ToMatrix() const
Returns matrix representation of this rotation.
Definition Rotation2d.h:195
constexpr double Cos() const
Returns the cosine of the rotation.
Definition Rotation2d.h:222
constexpr Rotation2d operator*(double scalar) const
Multiplies the current rotation by a scalar.
Definition Rotation2d.h:149
constexpr Rotation2d()=default
Constructs a Rotation2d with a default angle of 0 degrees.
constexpr double Sin() const
Returns the sine of the rotation.
Definition Rotation2d.h:229
constexpr units::radian_t Radians() const
Returns the radian value of the rotation constrained within [-π, π].
Definition Rotation2d.h:206
constexpr Rotation2d operator+(const Rotation2d &other) const
Adds two rotations together, with the result being bounded between -π and π.
Definition Rotation2d.h:115
constexpr Rotation2d(double x, double y)
Constructs a Rotation2d with the given x and y (cosine and sine) components.
Definition Rotation2d.h:49
Compile-time wrapper for Eigen::Matrix.
Definition ct_matrix.h:26
constexpr Scalar determinant() const
Constexpr version of Eigen's 2x2 matrix determinant member function.
Definition ct_matrix.h:316
static void ReportError(const S &format, Args &&... args)
Definition MathShared.h:48
Definition SystemServer.h:9
WPILIB_DLLEXPORT void to_json(wpi::json &json, const Rotation3d &rotation)
WPILIB_DLLEXPORT void from_json(const wpi::json &json, Rotation3d &rotation)
constexpr T abs(const T x) noexcept
Compile-time absolute value function.
Definition abs.hpp:40
constexpr common_return_t< T1, T2 > hypot(const T1 x, const T2 y) noexcept
Compile-time Pythagorean addition function.
Definition hypot.hpp:147
constexpr common_return_t< T1, T2 > atan2(const T1 y, const T2 x) noexcept
Compile-time two-argument arctangent function.
Definition atan2.hpp:88
Unit Conversion Library namespace.
Definition acceleration.h:33
std::string GetStackTrace(int offset)
Get a stack trace, ignoring the first "offset" symbols.
Type representing an arbitrary unit.
Definition base.h:888