39 : m_translation{
std::move(translation)},
40 m_rotation{
std::move(rotation)} {}
51 : m_translation{x, y}, m_rotation{
std::move(rotation)} {}
60 : m_translation{
Eigen::Vector2d{{matrix(0, 2)}, {matrix(1, 2)}}},
61 m_rotation{Eigen::Matrix2d{{matrix(0, 0), matrix(0, 1)},
62 {matrix(1, 0), matrix(1, 1)}}} {
63 if (matrix(2, 0) != 0.0 || matrix(2, 1) != 0.0 || matrix(2, 2) != 1.0) {
64 throw std::domain_error(
"Affine transformation matrix is invalid");
85 constexpr units::meter_t
X()
const {
return m_translation.X(); }
92 constexpr units::meter_t
Y()
const {
return m_translation.Y(); }
99 auto vec = m_translation.ToVector();
100 auto mat = m_rotation.ToMatrix();
101 return Eigen::Matrix3d{{mat(0, 0), mat(0, 1), vec(0)},
102 {mat(1, 0), mat(1, 1), vec(1)},
130 return Transform2d{(-Translation()).RotateBy(-Rotation()), -Rotation()};
140 return Transform2d(m_translation * scalar, m_rotation * scalar);
150 return *
this * (1.0 / scalar);
183 m_translation = (
final.Translation() - initial.
Translation())
186 m_rotation =
final.Rotation() - initial.
Rotation();
194 const auto dtheta = m_rotation.
Radians().value();
195 const auto halfDtheta = dtheta / 2.0;
197 const auto cosMinusOne = m_rotation.
Cos() - 1;
199 double halfThetaByTanOfHalfDtheta;
202 halfThetaByTanOfHalfDtheta = 1.0 - 1.0 / 12.0 * dtheta * dtheta;
204 halfThetaByTanOfHalfDtheta = -(halfDtheta * m_rotation.
Sin()) / cosMinusOne;
208 m_translation.
RotateBy({halfThetaByTanOfHalfDtheta, -halfDtheta}) *
209 gcem::hypot(halfThetaByTanOfHalfDtheta, halfDtheta);
211 return {translationPart.
X(), translationPart.
Y(), units::radian_t{dtheta}};
#define WPILIB_DLLEXPORT
Definition SymbolExports.h:36
Represents a 2D pose containing translational and rotational elements.
Definition Pose2d.h:27
constexpr Pose2d TransformBy(const Transform2d &other) const
Transforms the pose by the given transformation and returns the new pose.
Definition Pose2d.h:287
constexpr const Rotation2d & Rotation() const
Returns the underlying rotation.
Definition Pose2d.h:127
constexpr const Translation2d & Translation() const
Returns the underlying translation.
Definition Pose2d.h:106
A rotation in a 2D coordinate frame represented by a point on the unit circle (cosine and sine).
Definition Rotation2d.h:26
constexpr double Cos() const
Returns the cosine of the rotation.
Definition Rotation2d.h:222
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
Represents a translation in 2D space.
Definition Translation2d.h:30
constexpr units::meter_t X() const
Returns the X component of the translation.
Definition Translation2d.h:101
constexpr Translation2d RotateBy(const Rotation2d &other) const
Applies a rotation to the translation in 2D space.
Definition Translation2d.h:164
constexpr units::meter_t Y() const
Returns the Y component of the translation.
Definition Translation2d.h:108
Definition variable.hpp:742
Definition SystemServer.h:9
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
Definition PointerIntPair.h:280
A change in distance along a 2D arc since the last pose update.
Definition Twist2d.h:24