4#include "core/math/eigen_interface.h"
5#include "core/math/units.h"
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) {
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_}}; }
127 return Rotation2d(cos_ * other.cos_ - sin_ * other.sin_, cos_ * other.sin_ + sin_ * other.cos_);
147 return rotation * scalar;
161 return cos_ == other.cos_ && sin_ == other.sin_;
166 return units::abs((*
this - other).
angle()) <= tolerance;
175 static constexpr double deg2rad(
double deg) {
return deg * (std::numbers::pi / 180.0); }
183 static constexpr double rad2deg(
double rad) {
return rad * (180.0 / std::numbers::pi); }
192 if (
angle >= -std::numbers::pi &&
angle <= std::numbers::pi) {
195 double x = cevalm::fmod(
angle, 2 * std::numbers::pi);
196 if (x > std::numbers::pi) {
197 x -= 2 * std::numbers::pi;
198 }
else if (x < -std::numbers::pi) {
199 x += 2 * std::numbers::pi;
214 double x = cevalm::fmod(
angle, 360.0);
217 }
else if (x < -180.0) {
233 double x = cevalm::fmod(
angle, 1.0);
236 }
else if (x < -0.5) {
252 double x = cevalm::fmod(
angle, 400.0);
255 }
else if (x < -200.0) {
268 if (
angle >= 0.0 &&
angle < 2 * std::numbers::pi) {
271 double x = cevalm::fmod(
angle, 2 * std::numbers::pi);
273 x += 2 * std::numbers::pi;
275 return (x >= 2 * std::numbers::pi) ? 0.0 : x;
288 double x = cevalm::fmod(
angle, 360.0);
292 return (x >= 360.0) ? 0.0 : x;
305 double x = cevalm::fmod(
angle, 1.0);
309 return (x >= 1.0) ? 0.0 : x;
322 double x = cevalm::fmod(
angle, 400.0);
326 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:151
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:210
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:301
static constexpr double wrap_gradians_360(double angle)
Definition rotation2d.h:318
constexpr Rotation2d(double x, double y)
Definition rotation2d.h:40
constexpr Rotation2d & operator/=(double scalar)
Divides this rotation by a scalar.
Definition rotation2d.h:157
constexpr Rotation2d operator-(Rotation2d other) const
Subtracts another rotation from this rotation.
Definition rotation2d.h:134
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:248
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:143
static constexpr double wrap_radians_180(double angle)
Definition rotation2d.h:191
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:131
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:229
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:140
static constexpr double rad2deg(double rad)
Definition rotation2d.h:183
constexpr bool operator==(Rotation2d other) const
Checks exact equality between this rotation and another rotation.
Definition rotation2d.h:160
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:146
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:137
static constexpr double deg2rad(double deg)
Definition rotation2d.h:175
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:165
static constexpr double wrap_radians_360(double angle)
Definition rotation2d.h:267
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:284
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:154
constexpr double f_cos() const
Gets the cosine of the rotation.
Definition rotation2d.h:84