38 : m_translation{
std::move(translation)},
39 m_rotation{
std::move(rotation)} {}
49 constexpr Transform2d(wpi::units::meter_t x, wpi::units::meter_t y,
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 wpi::units::meter_t
X()
const {
return m_translation.X(); }
92 constexpr wpi::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)},
140 return Transform2d(m_translation * scalar, m_rotation * scalar);
150 return *
this * (1.0 / scalar);
182 m_translation = (
final.Translation() - initial.
Translation())
185 m_rotation =
final.Rotation().RelativeTo(initial.
Rotation());
193 const auto dtheta = m_rotation.Radians().value();
194 const auto halfDtheta = dtheta / 2.0;
196 const auto cosMinusOne = m_rotation.Cos() - 1;
198 double halfThetaByTanOfHalfDtheta;
201 halfThetaByTanOfHalfDtheta = 1.0 - 1.0 / 12.0 * dtheta * dtheta;
203 halfThetaByTanOfHalfDtheta = -(halfDtheta * m_rotation.Sin()) / cosMinusOne;
207 m_translation.
RotateBy({halfThetaByTanOfHalfDtheta, -halfDtheta}) *
208 gcem::hypot(halfThetaByTanOfHalfDtheta, halfDtheta);
210 return {translationPart.
X(), translationPart.
Y(),
211 wpi::units::radian_t{dtheta}};
#define WPILIB_DLLEXPORT
Definition SymbolExports.hpp:36
Represents a 2D pose containing translational and rotational elements.
Definition Pose2d.hpp:27
constexpr const Translation2d & Translation() const
Returns the underlying translation.
Definition Pose2d.hpp:107
constexpr const Rotation2d & Rotation() const
Returns the underlying rotation.
Definition Pose2d.hpp:128
constexpr Pose2d TransformBy(const Transform2d &other) const
Transforms the pose by the given transformation and returns the new pose.
Definition Pose2d.hpp:287
A rotation in a 2D coordinate frame represented by a point on the unit circle (cosine and sine).
Definition Rotation2d.hpp:26
Represents a translation in 2D space.
Definition Translation2d.hpp:30
constexpr Translation2d RotateBy(const Rotation2d &other) const
Applies a rotation to the translation in 2D space.
Definition Translation2d.hpp:167
constexpr wpi::units::meter_t Y() const
Returns the Y component of the translation.
Definition Translation2d.hpp:109
constexpr wpi::units::meter_t X() const
Returns the X component of the translation.
Definition Translation2d.hpp:102
Definition variable.hpp:916
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 StringMap.hpp:773
Definition LinearSystem.hpp:20
A change in distance along a 2D arc since the last pose update.
Definition Twist2d.hpp:23