4#include "core/math/eigen_interface.h"
5#include "core/math/units.h"
26 constexpr Rotation2d(units::Angle value) : cos_(units::cos(value)), sin_(units::sin(value)) {}
29 constexpr Rotation2d(
double value) : cos_(cevalm::cos(value)), sin_(cevalm::sin(value)) {}
41 double mag = cevalm::hypot(x, y);
42 if (x != 0 || y != 0) {
61 :
Rotation2d(x.to(units::inches), y.to(units::inches)) {}
64 constexpr units::Angle
angle()
const {
65 return units::Angle(cevalm::atan2(sin_, cos_), units::radians);
69 constexpr double angle(units::Angle unit)
const {
return angle().to(unit); }
72 constexpr double radians()
const {
return angle().to(units::radians); }
75 constexpr double degrees()
const {
return angle().to(units::degrees); }
81 constexpr double gradians()
const {
return angle().to(units::gradians); }
84 constexpr double f_cos()
const {
return cos_; }
87 constexpr double f_sin()
const {
return sin_; }
90 constexpr double f_tan()
const {
return sin_ / cos_; }
99 constexpr EMat<2, 2>
rotation_matrix()
const {
return EMat<2, 2>{{cos_, -sin_}, {sin_, cos_}}; }
128 cos_ * other.cos_ - sin_ * other.sin_, cos_ * other.sin_ + sin_ * other.cos_
149 return rotation * scalar;
163 return cos_ == other.cos_ && sin_ == other.sin_;
168 return units::abs((*
this - other).
angle()) <= tolerance;
177 static constexpr double deg2rad(
double deg) {
return deg * (std::numbers::pi / 180.0); }
185 static constexpr double rad2deg(
double rad) {
return rad * (180.0 / std::numbers::pi); }
194 if (
angle >= -std::numbers::pi &&
angle <= std::numbers::pi) {
197 double x = cevalm::fmod(
angle, 2 * std::numbers::pi);
198 if (x > std::numbers::pi) {
199 x -= 2 * std::numbers::pi;
200 }
else if (x < -std::numbers::pi) {
201 x += 2 * std::numbers::pi;
216 double x = cevalm::fmod(
angle, 360.0);
219 }
else if (x < -180.0) {
235 double x = cevalm::fmod(
angle, 1.0);
238 }
else if (x < -0.5) {
254 double x = cevalm::fmod(
angle, 400.0);
257 }
else if (x < -200.0) {
270 if (
angle >= 0.0 &&
angle < 2 * std::numbers::pi) {
273 double x = cevalm::fmod(
angle, 2 * std::numbers::pi);
275 x += 2 * std::numbers::pi;
277 return (x >= 2 * std::numbers::pi) ? 0.0 : x;
290 double x = cevalm::fmod(
angle, 360.0);
294 return (x >= 360.0) ? 0.0 : x;
307 double x = cevalm::fmod(
angle, 1.0);
311 return (x >= 1.0) ? 0.0 : x;
324 double x = cevalm::fmod(
angle, 400.0);
328 return (x >= 400.0) ? 0.0 : x;
constexpr double wrapped_revolutions_180() const
Gets the value of this rotation in revolutions from [-0.5, 0.5].
Definition rotation2d.h:108
constexpr Rotation2d & operator*=(double scalar)
Multiplies this rotation by a scalar.
Definition rotation2d.h:153
constexpr double radians() const
Gets the rotation in radians.
Definition rotation2d.h:72
constexpr double f_sin() const
Gets the sine of the rotation.
Definition rotation2d.h:87
static constexpr double wrap_degrees_180(double angle)
Definition rotation2d.h:212
constexpr double wrapped_gradians_180() const
Gets the value of this rotation in gradians from [-200, 200].
Definition rotation2d.h:111
constexpr Rotation2d(units::Length x, units::Length y)
Definition rotation2d.h:60
static constexpr double wrap_revolutions_360(double angle)
Definition rotation2d.h:303
static constexpr double wrap_gradians_360(double angle)
Definition rotation2d.h:320
constexpr Rotation2d(double x, double y)
Definition rotation2d.h:40
constexpr Rotation2d & operator/=(double scalar)
Divides this rotation by a scalar.
Definition rotation2d.h:159
constexpr Rotation2d operator-(Rotation2d other) const
Subtracts another rotation from this rotation.
Definition rotation2d.h:136
constexpr double revolutions() const
Gets the rotation in revolutions.
Definition rotation2d.h:78
constexpr double wrapped_degrees_180() const
Gets the value of this rotation in degrees from [-180, 180].
Definition rotation2d.h:105
constexpr double degrees() const
Gets the rotation in degrees.
Definition rotation2d.h:75
constexpr double f_tan() const
Gets the tangent of the rotation.
Definition rotation2d.h:90
static constexpr double wrap_gradians_180(double angle)
Definition rotation2d.h:250
constexpr double wrapped_degrees_360() const
Gets the value of this rotation in degrees from [0, 360).
Definition rotation2d.h:117
constexpr double wrapped_gradians_360() const
Gets the value of this rotation in gradians from [0, 400).
Definition rotation2d.h:123
constexpr Rotation2d(units::Angle value)
Constructs a rotation given a units::Angle.
Definition rotation2d.h:26
constexpr Rotation2d operator*(double scalar) const
Multiplies this rotation by a scalar.
Definition rotation2d.h:145
static constexpr double wrap_radians_180(double angle)
Definition rotation2d.h:193
constexpr units::Angle angle() const
Gets an Angle equal to this rotation.
Definition rotation2d.h:64
constexpr Rotation2d & operator+=(Rotation2d other)
Adds another rotation to this rotation.
Definition rotation2d.h:133
constexpr double angle(units::Angle unit) const
Gets the angle in the supplied unit.
Definition rotation2d.h:69
static constexpr double wrap_revolutions_180(double angle)
Definition rotation2d.h:231
constexpr Rotation2d operator+(Rotation2d other) const
Adds another rotation to this rotation.
Definition rotation2d.h:126
constexpr Rotation2d operator-() const
Inverts this rotation (conjugate).
Definition rotation2d.h:142
static constexpr double rad2deg(double rad)
Definition rotation2d.h:185
constexpr bool operator==(Rotation2d other) const
Checks exact equality between this rotation and another rotation.
Definition rotation2d.h:162
constexpr Rotation2d()=default
Default Constructor for Rotation2d.
constexpr double gradians() const
Gets the rotation in gradians.
Definition rotation2d.h:81
friend constexpr Rotation2d operator*(double scalar, Rotation2d rotation)
Multiplies a scalar by this rotation.
Definition rotation2d.h:148
constexpr double wrapped_radians_180() const
Gets the value of this rotation in radians from [-pi, pi].
Definition rotation2d.h:102
constexpr Rotation2d & operator-=(Rotation2d other)
Subtracts another rotation from this rotation.
Definition rotation2d.h:139
static constexpr double deg2rad(double deg)
Definition rotation2d.h:177
constexpr Rotation2d inverse() const
Inverts this rotation (conjugate).
Definition rotation2d.h:93
constexpr Rotation2d(double value)
Constructs a rotation given an angle in radians.
Definition rotation2d.h:29
constexpr Rotation2d opposite() const
Flips this rotation across the origin.
Definition rotation2d.h:96
constexpr EMat< 2, 2 > rotation_matrix() const
Gets the rotation matrix corresponding to this rotation.
Definition rotation2d.h:99
constexpr bool is_near(Rotation2d other, units::Angle tolerance=units::Angle(1e-6)) const
Compares two angles with a default tolerance of 1e-6 radians.
Definition rotation2d.h:167
static constexpr double wrap_radians_360(double angle)
Definition rotation2d.h:269
constexpr double wrapped_radians_360() const
Gets the value of this rotation in radians from [0, 2pi).
Definition rotation2d.h:114
static constexpr double wrap_degrees_360(double angle)
Definition rotation2d.h:286
constexpr double wrapped_revolutions_360() const
Gets the value of this rotation in revolutions from [0, 1).
Definition rotation2d.h:120
constexpr Rotation2d operator/(double scalar) const
Divides this rotation by a scalar.
Definition rotation2d.h:156
constexpr double f_cos() const
Gets the cosine of the rotation.
Definition rotation2d.h:84