RIT VEXU Core API
Loading...
Searching...
No Matches
transform2d.h
1#pragma once
2
3#include "core/math/geometry/rotation2d.h"
4#include "core/math/geometry/translation2d.h"
5#include "core/math/units.h"
6
18 private:
19 Translation2d translation_;
20 Rotation2d rotation_;
21
22 public:
24 constexpr Transform2d() = default;
25
32 constexpr Transform2d(Translation2d translation, Rotation2d rotation)
33 : translation_(translation), rotation_(rotation) {}
34
42 constexpr Transform2d(units::Length x, units::Length y, Rotation2d rotation)
43 : translation_(x, y), rotation_(rotation) {}
44
52 constexpr Transform2d(units::Length x, units::Length y, units::Angle angle)
53 : translation_(x, y), rotation_(angle) {}
54
61 constexpr Transform2d(Translation2d translation, units::Angle angle)
62 : translation_(translation), rotation_(angle) {}
63
72 constexpr Transform2d(
73 const Eigen::Vector3d& transform_vector, units::Length unit,
74 units::Angle angle_unit = units::radians
75 )
76 : translation_({transform_vector(0), transform_vector(1)}, unit),
77 rotation_(units::Angle(transform_vector(2), angle_unit)) {}
78
80 constexpr units::Length x() const { return translation_.x(); }
81
83 constexpr double x(units::Length unit) const { return translation_.x(unit); }
84
86 constexpr void set_x(units::Length val) { translation_.set_x(val); }
87
89 constexpr units::Length y() const { return translation_.y(); }
90
92 constexpr double y(units::Length unit) const { return translation_.y(unit); }
93
95 constexpr void set_y(units::Length val) { translation_.set_y(val); }
96
98 constexpr Translation2d translation() const { return translation_; }
99
101 constexpr void set_translation(Translation2d val) { translation_ = val; }
102
104 constexpr Rotation2d rotation() const { return rotation_; }
105
107 constexpr void set_rotation(Rotation2d val) { rotation_ = val; }
108
110 constexpr units::Angle angle() const { return rotation_.angle(); }
111
113 constexpr double angle(units::Angle unit) const { return rotation_.angle(unit); }
114
116 constexpr void set_angle(units::Angle val) { rotation_ = Rotation2d(val); }
117
125 EVec<3> as_vector(units::Length length_unit, units::Angle angle_unit = units::radians) const {
126 return {translation_.x().to(length_unit), translation_.y().to(length_unit),
127 rotation_.angle().to(angle_unit)};
128 }
129
131 constexpr Transform2d inverse() const {
132 return Transform2d(-translation_.rotate_by(-rotation_), -rotation_);
133 }
134
136 constexpr Transform2d operator+(const Transform2d& other) const {
137 return {translation_ + other.translation_.rotate_by(rotation_),
138 rotation_ + other.rotation_};
139 }
140
142 constexpr Transform2d& operator+=(const Transform2d& other) { return *this = *this + other; }
143
145 constexpr Transform2d operator-() const { return inverse(); }
146
148 constexpr Transform2d operator*(double scalar) const {
149 return Transform2d(translation_ * scalar, rotation_ * scalar);
150 }
151
153 friend constexpr Transform2d operator*(double scalar, const Transform2d& transform) {
154 return transform * scalar;
155 }
156
158 constexpr Transform2d& operator*=(double scalar) { return *this = *this * scalar; }
159
161 constexpr Transform2d operator/(double scalar) const {
162 return Transform2d(translation_ / scalar, rotation_ / scalar);
163 }
164
166 constexpr Transform2d& operator/=(double scalar) { return *this = *this / scalar; }
167
169 constexpr bool operator==(const Transform2d& other) const {
170 return (translation_ == other.translation_) && (rotation_ == other.rotation_);
171 }
172
177 constexpr bool is_near(
178 const Transform2d& other, units::Length distance_tolerance = units::Length(1e-6),
179 units::Angle angle_tolerance = units::Angle(1e-6)
180 ) const {
181 return translation_.is_near(other.translation_, distance_tolerance) &&
182 rotation_.is_near(other.rotation_, angle_tolerance);
183 }
184};
constexpr LinearVector2d rotate_by(Rotation2d rotation) const
Definition translation2d.h:140
Definition rotation2d.h:16
constexpr Rotation2d()=default
Default Constructor for Rotation2d.
constexpr double x(units::Length unit) const
Gets x in the supplied length unit.
Definition transform2d.h:83
constexpr Transform2d()=default
Default Constructor for Transform2d.
constexpr Transform2d operator/(double scalar) const
Divides this transform by a scalar.
Definition transform2d.h:161
constexpr void set_angle(units::Angle val)
Sets the rotation as an angle.
Definition transform2d.h:116
constexpr Transform2d & operator*=(double scalar)
Multiplies this transform by a scalar.
Definition transform2d.h:158
constexpr units::Angle angle() const
Gets the rotation as an Angle.
Definition transform2d.h:110
constexpr Transform2d operator+(const Transform2d &other) const
Composes this transform and another transform.
Definition transform2d.h:136
constexpr Translation2d translation() const
Gets the translation.
Definition transform2d.h:98
constexpr void set_translation(Translation2d val)
Sets the translation.
Definition transform2d.h:101
constexpr double y(units::Length unit) const
Gets y in the supplied length unit.
Definition transform2d.h:92
constexpr void set_y(units::Length val)
Sets the y component.
Definition transform2d.h:95
constexpr Transform2d(Translation2d translation, units::Angle angle)
Definition transform2d.h:61
constexpr Transform2d inverse() const
Inverts this transform.
Definition transform2d.h:131
constexpr Transform2d(const Eigen::Vector3d &transform_vector, units::Length unit, units::Angle angle_unit=units::radians)
Definition transform2d.h:72
constexpr void set_x(units::Length val)
Sets the x component.
Definition transform2d.h:86
constexpr Rotation2d rotation() const
Gets the rotation.
Definition transform2d.h:104
constexpr Transform2d(units::Length x, units::Length y, Rotation2d rotation)
Definition transform2d.h:42
constexpr bool is_near(const Transform2d &other, units::Length distance_tolerance=units::Length(1e-6), units::Angle angle_tolerance=units::Angle(1e-6)) const
Definition transform2d.h:177
constexpr Transform2d & operator/=(double scalar)
Divides this transform by a scalar.
Definition transform2d.h:166
constexpr Transform2d(Translation2d translation, Rotation2d rotation)
Definition transform2d.h:32
friend constexpr Transform2d operator*(double scalar, const Transform2d &transform)
Multiplies this transform by a scalar reverse order.
Definition transform2d.h:153
constexpr Transform2d(units::Length x, units::Length y, units::Angle angle)
Definition transform2d.h:52
constexpr Transform2d operator-() const
Inverts this transform.
Definition transform2d.h:145
constexpr bool operator==(const Transform2d &other) const
Checks exact equality between this and another transform.
Definition transform2d.h:169
EVec< 3 > as_vector(units::Length length_unit, units::Angle angle_unit=units::radians) const
Definition transform2d.h:125
constexpr void set_rotation(Rotation2d val)
Sets the rotation.
Definition transform2d.h:107
constexpr units::Length x() const
Gets the x component.
Definition transform2d.h:80
constexpr double angle(units::Angle unit) const
Gets the angle in the supplied unit.
Definition transform2d.h:113
constexpr units::Length y() const
Gets the y component.
Definition transform2d.h:89
constexpr Transform2d operator*(double scalar) const
Multiplies this transform by a scalar.
Definition transform2d.h:148
constexpr Transform2d & operator+=(const Transform2d &other)
Composes this transform and another transform.
Definition transform2d.h:142