6#include "core/math/geometry/rotation2d.h"
7#include "core/math/geometry/transform2d.h"
8#include "core/math/geometry/translation2d.h"
9#include "core/math/geometry/twist2d.h"
10#include "core/math/units.h"
23 Translation2d translation_;
56 constexpr Pose2d(units::Length
x, units::Length
y,
double radians)
57 : translation_{
x,
y}, rotation_{radians} {}
68 const Eigen::Vector3d& pose_vector, units::Length length_unit,
69 units::Angle angle_unit = units::radians
72 units::Length(pose_vector[0], length_unit),
73 units::Length(pose_vector[1], length_unit)
75 rotation_{units::Angle(pose_vector[2], angle_unit)} {}
78 constexpr units::Length
x()
const {
return translation_.x(); }
81 constexpr double x(units::Length unit)
const {
return translation_.x(unit); }
84 constexpr void set_x(units::Length val) { translation_.set_x(val); }
87 constexpr units::Length
y()
const {
return translation_.y(); }
90 constexpr double y(units::Length unit)
const {
return translation_.y(unit); }
93 constexpr void set_y(units::Length val) { translation_.set_y(val); }
96 constexpr Translation2d
translation()
const {
return translation_; }
108 constexpr units::Angle
angle()
const {
return rotation_.angle(); }
111 constexpr double angle(units::Angle unit)
const {
return rotation_.angle(unit); }
117 EVec<3>
as_vector(units::Length length_unit, units::Angle angle_unit = units::radians)
const {
118 return {translation_.x().to(length_unit), translation_.y().to(length_unit),
119 rotation_.angle().to(angle_unit)};
123 constexpr units::Length
distance(Translation2d point)
const {
124 return translation_.distance(point);
129 return distance(other.translation_);
134 const auto delta = point - translation_;
135 if (delta.x().internal() == 0 && delta.y().internal() == 0) {
138 return delta.
theta();
142 constexpr units::Angle
angle_to(Translation2d point)
const {
143 return (
bearing_to(point) - rotation_).angle();
148 return translation_ + point.
rotate_by(rotation_);
153 return (point - translation_).
rotate_by(-rotation_);
177 translation_ + (transform.
translation().rotate_by(rotation_)),
195 return {translation_ + (end.translation_ - translation_) * fraction,
196 rotation_ + (end.rotation_ - rotation_) * fraction};
219 const units::Length dx = twist.
dx();
220 const units::Length dy = twist.
dy();
221 const double dtheta = twist.
dtheta().to(units::radians);
223 const double sin_theta = cevalm::sin(dtheta);
224 const double cos_theta = cevalm::cos(dtheta);
227 if (cevalm::abs(dtheta) < 1e-9) {
228 s = 1.0 - 1.0 / 6.0 * dtheta * dtheta;
231 s = sin_theta / dtheta;
232 c = (1 - cos_theta) / dtheta;
236 Translation2d{dx * s - dy * c, dx * c + dy * s},
Rotation2d{cos_theta, sin_theta}
239 return *
this + transform;
252 const double half_dtheta = dtheta / 2.0;
254 const double cos_minus_one = transform.
rotation().
f_cos() - 1;
256 double half_theta_by_tan_of_half_dtheta;
258 if (cevalm::abs(cos_minus_one) < 1e-9) {
259 half_theta_by_tan_of_half_dtheta = 1.0 - 1.0 / 12.0 * dtheta * dtheta;
261 half_theta_by_tan_of_half_dtheta =
262 -(half_dtheta * transform.
rotation().f_sin()) / cos_minus_one;
265 const Translation2d translation_part =
267 {half_theta_by_tan_of_half_dtheta, -half_dtheta}
269 cevalm::hypot(half_theta_by_tan_of_half_dtheta, half_dtheta);
272 translation_part.
x(), translation_part.
y(), units::Angle(dtheta, units::radians)
283 if (list.size() == 0) {
293 for (
Pose2d pose : list) {
297 sum_sin += pose.rotation_.f_sin();
298 sum_cos += pose.rotation_.f_cos();
302 Translation2d{sumx / list.size(), sumy / list.size()},
303 Rotation2d{sum_cos / list.size(), sum_sin / list.size()}
310 translation_ + (transform.
translation().rotate_by(rotation_)),
321 (translation_ - other.translation_).rotate_by(-other.rotation_),
322 rotation_ - other.rotation_
328 return (translation_ == other.translation_) && (rotation_ == other.rotation_);
336 const Pose2d& other, units::Length distance_tolerance = units::Length(1e-6),
337 units::Angle angle_tolerance = units::Angle(1e-6)
339 return translation_.is_near(other.translation_, distance_tolerance) &&
340 rotation_.is_near(other.rotation_, angle_tolerance);
constexpr Rotation2d theta() const
Gets the angle of the vector from the x axis.
Definition translation2d.h:83
constexpr Q x() const
Gets the x component.
Definition translation2d.h:65
constexpr LinearVector2d rotate_by(Rotation2d rotation) const
Definition translation2d.h:140
constexpr Q y() const
Gets the y component.
Definition translation2d.h:74
constexpr Pose2d & operator+=(const Transform2d &transform)
Adds a transform to this pose by rotating it into the pose frame then adding.
Definition pose2d.h:316
constexpr void set_angle(units::Angle val)
Sets the rotation as an angle.
Definition pose2d.h:114
constexpr Rotation2d rotation() const
Gets the rotation.
Definition pose2d.h:102
constexpr Pose2d exp(const Twist2d &twist) const
Definition pose2d.h:218
constexpr void set_rotation(Rotation2d val)
Sets the rotation.
Definition pose2d.h:105
constexpr units::Length distance(Translation2d point) const
Calculates the distance from the pose to another point.
Definition pose2d.h:123
constexpr Pose2d(units::Length x, units::Length y, Rotation2d rotation)
Definition pose2d.h:46
constexpr Pose2d transform_by(const Transform2d &transform) const
Definition pose2d.h:175
constexpr void set_y(units::Length val)
Sets the y value of the translation.
Definition pose2d.h:93
constexpr units::Angle angle() const
Gets the heading as an angle.
Definition pose2d.h:108
constexpr void set_x(units::Length val)
Sets the x value of the translation.
Definition pose2d.h:84
constexpr Rotation2d bearing_to(Translation2d point) const
Calculates the bearing from this to another point in the world frame.
Definition pose2d.h:133
EVec< 3 > as_vector(units::Length length_unit, units::Angle angle_unit=units::radians) const
Gets [x, y, theta] in the supplied units. Angles default to radians.
Definition pose2d.h:117
constexpr units::Length y() const
Gets the y value of the translation.
Definition pose2d.h:87
constexpr void set_translation(Translation2d val)
Sets the translation.
Definition pose2d.h:99
constexpr Pose2d(Translation2d translation, Rotation2d rotation)
Definition pose2d.h:36
constexpr Twist2d log(const Transform2d &transform) const
Definition pose2d.h:250
static Pose2d wrapped_mean(const std::vector< Pose2d > &list)
Definition pose2d.h:282
constexpr Pose2d(const Eigen::Vector3d &pose_vector, units::Length length_unit, units::Angle angle_unit=units::radians)
Definition pose2d.h:67
constexpr Pose2d interpolate(const Pose2d &end, double fraction) const
Definition pose2d.h:188
constexpr Translation2d world_to_local(Translation2d point) const
Converts a point from the world frame to this pose's local frame.
Definition pose2d.h:152
constexpr units::Length distance(const Pose2d &other) const
Calculates the distance from this to another pose, ignoring rotation.
Definition pose2d.h:128
constexpr Translation2d translation() const
Gets the translation.
Definition pose2d.h:96
constexpr Translation2d local_to_world(Translation2d point) const
Converts a point from this pose's local frame to the world frame.
Definition pose2d.h:147
constexpr double angle(units::Angle unit) const
Gets the angle in the supplied unit.
Definition pose2d.h:111
constexpr double y(units::Length unit) const
Gets y in the supplied length unit.
Definition pose2d.h:90
constexpr units::Angle angle_to(Translation2d point) const
Calculates the smallest angle to another point in the local frame.
Definition pose2d.h:142
constexpr double x(units::Length unit) const
Gets x in the supplied length unit.
Definition pose2d.h:81
constexpr Pose2d operator+(const Transform2d &transform) const
Adds a transform to this pose by rotating it into the pose frame then adding.
Definition pose2d.h:308
constexpr bool operator==(const Pose2d &other) const
Checks exact equality between this and another pose.
Definition pose2d.h:327
constexpr units::Length x() const
Gets the x value of the translation.
Definition pose2d.h:78
constexpr Transform2d operator-(const Pose2d &other) const
Subtracts another pose from this to find the transform between them.
Definition pose2d.h:319
constexpr Pose2d relative_to(const Pose2d &other) const
Definition pose2d.h:162
constexpr bool is_near(const Pose2d &other, units::Length distance_tolerance=units::Length(1e-6), units::Angle angle_tolerance=units::Angle(1e-6)) const
Definition pose2d.h:335
constexpr Pose2d()
Default Constructor for Pose2d.
Definition pose2d.h:28
constexpr Pose2d(units::Length x, units::Length y, double radians)
Definition pose2d.h:56
Definition rotation2d.h:16
constexpr double radians() const
Gets the rotation in radians.
Definition rotation2d.h:72
constexpr Rotation2d()=default
Default Constructor for Rotation2d.
constexpr double f_cos() const
Gets the cosine of the rotation.
Definition rotation2d.h:84
constexpr units::Length dx() const
Gets the x displacement.
Definition twist2d.h:56
constexpr units::Length dy() const
Gets the y displacement.
Definition twist2d.h:65
constexpr units::Angle dtheta() const
Gets the Angle displacement.
Definition twist2d.h:74