15 : position_(Eigen::Vector3d::Zero()), orientation_(Eigen::Quaterniond::Identity())
20Pose::Pose(
const Eigen::Vector3d &position,
const Eigen::Quaterniond &orientation)
21 : position_(position),
22 orientation_(orientation.normalized())
27Pose::Pose(
const Eigen::Vector3d &position,
const Eigen::Matrix3d &rotation_matrix)
28 : position_(position), orientation_(Eigen::Quaterniond(rotation_matrix))
35 : position_(transformation.translation()),
36 orientation_(Eigen::Quaterniond(transformation.rotation()))
43 : position_(position), orientation_(orientation.toQuaternion())
54 position_ = homogeneousT.block<3, 1>(0, 3);
57 const Eigen::Matrix3d rotation_matrix = homogeneousT.block<3, 3>(0, 0);
58 orientation_ = Eigen::Quaterniond(rotation_matrix).normalized();
68Pose::Pose(
const Pose &other) : position_(other.position_), orientation_(other.orientation_)
74 : position_(std::move(other.position_)), orientation_(std::move(other.orientation_))
94 position_ = std::move(other.position_);
95 orientation_ = std::move(other.orientation_);
119 Eigen::Affine3d transformation = Eigen::Affine3d::Identity();
120 transformation.translation() =
position_;
121 transformation.linear() =
orientation_.toRotationMatrix();
122 return transformation;
127 Eigen::Matrix4d homogeneous = Eigen::Matrix4d::Identity();
128 homogeneous.block<3, 3>(0, 0) =
orientation_.toRotationMatrix();
129 homogeneous.block<3, 1>(0, 3) =
position_;
184 orientation_ = Eigen::Quaterniond(rotation_matrix).normalized();
189 position_ = transformation.translation();
190 orientation_ = Eigen::Quaterniond(transformation.rotation()).normalized();
198 position_ = homogeneousT.block<3, 1>(0, 3);
201 const Eigen::Matrix3d rotation_matrix = homogeneousT.block<3, 3>(0, 0);
202 orientation_ = Eigen::Quaterniond(rotation_matrix).normalized();
216 dot = std::max(-1.0, std::min(1.0, dot));
217 return 2.0 * std::acos(dot);
225 return Pose(combined_position, combined_orientation);
231 const Eigen::Quaterniond inv_orientation =
orientation_.conjugate();
232 const Eigen::Vector3d inv_position = -(inv_orientation *
position_);
233 return Pose(inv_position, inv_orientation);
240 Eigen::RowVector4d expected_last_row(0, 0, 0, 1);
241 Eigen::RowVector4d actual_last_row = homogeneousT.block<1, 4>(3, 0);
243 if (!actual_last_row.isApprox(expected_last_row, 1e-6))
245 std::stringstream error_msg;
246 error_msg <<
"Invalid homogeneous transformation matrix. The last row must be [0, 0, 0, "
248 << actual_last_row(0) <<
", " << actual_last_row(1) <<
", " << actual_last_row(2)
249 <<
", " << actual_last_row(3) <<
"].";
250 throw std::invalid_argument(error_msg.str());
254 const Eigen::Matrix3d rotation_part = homogeneousT.block<3, 3>(0, 0);
258 Eigen::Matrix3d orthogonality_check = rotation_part * rotation_part.transpose();
259 Eigen::Matrix3d identity = Eigen::Matrix3d::Identity();
261 if (!orthogonality_check.isApprox(identity, 1e-6))
263 std::stringstream error_msg;
265 <<
"Invalid homogeneous transformation matrix. The rotation part is not orthogonal.";
266 throw std::invalid_argument(error_msg.str());
270 double det = rotation_part.determinant();
271 if (std::abs(det - 1.0) > 1e-6)
273 std::stringstream error_msg;
274 error_msg <<
"Invalid homogeneous transformation matrix. The rotation part has determinant "
275 << det <<
", which differs from 1.0 (expected for a proper rotation).";
276 throw std::invalid_argument(error_msg.str());
295 return transform * (*this);
Class representing a pose in 3D space.
Eigen::Vector3d globalToLocal(const Eigen::Vector3d &global_point) const
Transforms a point from the global frame to the pose's local frame.
double getQw() const
Gets the W component of the quaternion.
double getQz() const
Gets the Z component of the quaternion.
double getY() const
Gets the Y coordinate of the position.
double getQy() const
Gets the Y component of the quaternion.
Eigen::Quaterniond orientation_
Orientation represented as quaternion.
double positionDistance(const Pose &other) const
Calculates the Euclidean distance between the positions of two poses.
void setOrientation(const Eigen::Quaterniond &orientation)
Sets the orientation via quaternion.
double getX() const
Gets the X coordinate of the position.
Pose transformPose(const Pose &transform) const
Transforms this pose from one coordinate frame to another.
Eigen::Vector3d getPosition() const
Gets the position.
void setAffineTransformation(const Eigen::Affine3d &transformation)
Sets the affine transformation.
Eigen::Vector3d position_
Position in 3D space.
Pose() noexcept
Default constructor.
void setRotationMatrix(const Eigen::Matrix3d &rotation_matrix)
Sets the rotation matrix.
Eigen::Affine3d getAffineTransformation() const
Gets the affine transformation.
Eigen::Vector3d localToGlobal(const Eigen::Vector3d &local_point) const
Transforms a point from the pose's local frame to the global frame.
Pose & operator=(const Pose &other)
Copy assignment operator.
void setPosition(const Eigen::Vector3d &position)
Sets the position.
static void validateHomogeneousMatrix(const Eigen::Matrix4d &homogeneousT)
Validates a homogeneous transformation matrix.
double getQx() const
Gets the X component of the quaternion.
void setHomogeneousT(const Eigen::Matrix4d &homogeneousT)
Sets the homogeneous transformation matrix.
Pose inverse() const
Calculates the inverse of the pose.
Eigen::Quaterniond getQuaternion() const
Gets the orientation quaternion.
double getZ() const
Gets the Z coordinate of the position.
double orientationDistance(const Pose &other) const
Calculates the angular distance between the orientations of two poses.
Pose operator*(const Pose &other) const
Composition of two poses.
Eigen::Matrix3d getRotationMatrix() const
Gets the rotation matrix.
Eigen::Matrix4d getHomogeneousT() const
Gets the homogeneous transformation matrix.
Class for representing and managing rotations in three-dimensional space.
Namespace for movement and manipulation of poses.
std::ostream & operator<<(std::ostream &os, const Pose &pose)
Class for representing Poses.