39 : m_translation{
std::move(translation)},
40 m_rotation{
std::move(rotation)} {}
51 constexpr Transform3d(units::meter_t x, units::meter_t y, units::meter_t z,
53 : m_translation{x, y, z}, m_rotation{
std::move(rotation)} {}
62 : m_translation{
Eigen::Vector3d{
63 {matrix(0, 3)}, {matrix(1, 3)}, {matrix(2, 3)}}},
65 Eigen::Matrix3d{{matrix(0, 0), matrix(0, 1), matrix(0, 2)},
66 {matrix(1, 0), matrix(1, 1), matrix(1, 2)},
67 {matrix(2, 0), matrix(2, 1), matrix(2, 2)}}} {
68 if (matrix(3, 0) != 0.0 || matrix(3, 1) != 0.0 || matrix(3, 2) != 0.0 ||
69 matrix(3, 3) != 1.0) {
70 throw std::domain_error(
"Affine transformation matrix is invalid");
102 constexpr units::meter_t
X()
const {
return m_translation.X(); }
109 constexpr units::meter_t
Y()
const {
return m_translation.Y(); }
116 constexpr units::meter_t
Z()
const {
return m_translation.Z(); }
123 auto vec = m_translation.ToVector();
124 auto mat = m_rotation.ToMatrix();
125 return Eigen::Matrix4d{{mat(0, 0), mat(0, 1), mat(0, 2), vec(0)},
126 {mat(1, 0), mat(1, 1), mat(1, 2), vec(1)},
127 {mat(2, 0), mat(2, 1), mat(2, 2), vec(2)},
128 {0.0, 0.0, 0.0, 1.0}};
155 return Transform3d{(-Translation()).RotateBy(-Rotation()), -Rotation()};
165 return Transform3d(m_translation * scalar, m_rotation * scalar);
175 return *
this * (1.0 / scalar);
209 m_translation = (
final.Translation() - initial.
Translation())
212 m_rotation =
final.Rotation() - initial.
Rotation();
222 auto impl = [
this]<
typename Matrix3d,
typename Vector3d>() ->
Twist3d {
223 Vector3d u{{m_translation.
X().value(), m_translation.
Y().value(),
224 m_translation.
Z().value()}};
225 Vector3d rvec = m_rotation.
ToVector();
227 Matrix3d omegaSq = omega * omega;
228 double theta = rvec.norm();
229 double thetaSq = theta * theta;
244 C = 1 / 12.0 + thetaSq / 720 + thetaSq * thetaSq / 30240;
250 double B = (1 -
gcem::cos(theta)) / thetaSq;
251 C = (1 - A / (2 * B)) / thetaSq;
254 Matrix3d V_inv = Matrix3d::Identity() - 0.5 * omega + C * omegaSq;
256 Vector3d translation_component = V_inv * u;
258 return Twist3d{units::meter_t{translation_component(0)},
259 units::meter_t{translation_component(1)},
260 units::meter_t{translation_component(2)},
261 units::radian_t{rvec(0)},
262 units::radian_t{rvec(1)},
263 units::radian_t{rvec(2)}};
266 if (std::is_constant_evaluated()) {
269 return impl.template operator()<Eigen::Matrix3d, Eigen::Vector3d>();
#define WPILIB_DLLEXPORT
Definition SymbolExports.h:36
Represents a 3D pose containing translational and rotational elements.
Definition Pose3d.h:30
constexpr Pose3d TransformBy(const Transform3d &other) const
Transforms the pose by the given transformation and returns the new transformed pose.
Definition Pose3d.h:316
constexpr const Translation3d & Translation() const
Returns the underlying translation.
Definition Pose3d.h:122
constexpr const Rotation3d & Rotation() const
Returns the underlying rotation.
Definition Pose3d.h:150
A rotation in a 3D coordinate frame represented by a quaternion.
Definition Rotation3d.h:29
constexpr Eigen::Vector3d ToVector() const
Returns rotation vector representation of this rotation.
Definition Rotation3d.h:432
Represents a translation in 3D space.
Definition Translation3d.h:31
constexpr Translation3d RotateBy(const Rotation3d &other) const
Applies a rotation to the translation in 3D space.
Definition Translation3d.h:178
constexpr units::meter_t Y() const
Returns the Y component of the translation.
Definition Translation3d.h:130
constexpr units::meter_t X() const
Returns the X component of the translation.
Definition Translation3d.h:123
constexpr units::meter_t Z() const
Returns the Z component of the translation.
Definition Translation3d.h:137
Compile-time wrapper for Eigen::Matrix.
Definition ct_matrix.h:26
Definition variable.hpp:742
constexpr ct_matrix3d RotationVectorToMatrix(const ct_vector3d &rotation)
Definition RotationVectorToMatrix.h:13
Definition SystemServer.h:9
ct_matrix< double, 3, 3 > ct_matrix3d
Definition ct_matrix.h:385
constexpr T abs(const T x) noexcept
Compile-time absolute value function.
Definition abs.hpp:40
constexpr return_t< T > cos(const T x) noexcept
Compile-time cosine function.
Definition cos.hpp:83
constexpr return_t< T > sin(const T x) noexcept
Compile-time sine function.
Definition sin.hpp:85
Definition PointerIntPair.h:280
A change in distance along a 3D arc since the last pose update.
Definition Twist3d.h:24