MoveG 1.0.0
A modern C++ library for Robotics
Loading...
Searching...
No Matches
MoveG::Pose Class Reference

Class representing a pose in 3D space. More...

#include <pose_lib.h>

+ Collaboration diagram for MoveG::Pose:

Public Member Functions

 Pose () noexcept
 Default constructor.
 
 Pose (const Eigen::Vector3d &position, const Eigen::Quaterniond &orientation)
 Constructor with position and quaternion orientation.
 
 Pose (const Eigen::Vector3d &position, const Eigen::Matrix3d &rotation_matrix)
 Constructor with position and rotation matrix.
 
 Pose (const Eigen::Affine3d &transformation)
 Constructor with affine transformation.
 
 Pose (const Eigen::Vector3d &position, const Rotation &orientation)
 Constructor with position and Rotation object.
 
 Pose (const Eigen::Matrix4d &homogeneousT)
 Constructor with homogeneous transformation matrix 4x4.
 
 ~Pose ()
 Destructor.
 
 Pose (const Pose &other)
 Copy constructor.
 
 Pose (Pose &&other) noexcept
 Move constructor.
 
Poseoperator= (const Pose &other)
 Copy assignment operator.
 
Poseoperator= (Pose &&other) noexcept
 Move assignment operator.
 
Eigen::Vector3d getPosition () const
 Gets the position.
 
Eigen::Quaterniond getQuaternion () const
 Gets the orientation quaternion.
 
Eigen::Matrix3d getRotationMatrix () const
 Gets the rotation matrix.
 
Eigen::Affine3d getAffineTransformation () const
 Gets the affine transformation.
 
Eigen::Matrix4d getHomogeneousT () const
 Gets the homogeneous transformation matrix.
 
double getX () const
 Gets the X coordinate of the position.
 
double getY () const
 Gets the Y coordinate of the position.
 
double getZ () const
 Gets the Z coordinate of the position.
 
double getQx () const
 Gets the X component of the quaternion.
 
double getQy () const
 Gets the Y component of the quaternion.
 
double getQz () const
 Gets the Z component of the quaternion.
 
double getQw () const
 Gets the W component of the quaternion.
 
void setPosition (const Eigen::Vector3d &position)
 Sets the position.
 
void setOrientation (const Eigen::Quaterniond &orientation)
 Sets the orientation via quaternion.
 
void setRotationMatrix (const Eigen::Matrix3d &rotation_matrix)
 Sets the rotation matrix.
 
void setAffineTransformation (const Eigen::Affine3d &transformation)
 Sets the affine transformation.
 
void setHomogeneousT (const Eigen::Matrix4d &homogeneousT)
 Sets the homogeneous transformation matrix.
 
double positionDistance (const Pose &other) const
 Calculates the Euclidean distance between the positions of two poses.
 
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.
 
Pose inverse () const
 Calculates the inverse of the pose.
 
Pose transformPose (const Pose &transform) const
 Transforms this pose from one coordinate frame to another.
 
Eigen::Vector3d localToGlobal (const Eigen::Vector3d &local_point) const
 Transforms a point from the pose's local frame to the global frame.
 
Eigen::Vector3d globalToLocal (const Eigen::Vector3d &global_point) const
 Transforms a point from the global frame to the pose's local frame.
 

Static Private Member Functions

static void validateHomogeneousMatrix (const Eigen::Matrix4d &homogeneousT)
 Validates a homogeneous transformation matrix.
 

Private Attributes

Eigen::Vector3d position_
 Position in 3D space.
 
Eigen::Quaterniond orientation_
 Orientation represented as quaternion.
 

Friends

std::ostream & operator<< (std::ostream &os, const Pose &pose)
 Overloads the stream insertion operator.
 

Detailed Description

Class representing a pose in 3D space.

The Pose class encapsulates a position and orientation in three-dimensional space. It uses Eigen for mathematical operations related to geometry.

Definition at line 34 of file pose_lib.h.

Constructor & Destructor Documentation

◆ Pose() [1/8]

MoveG::Pose::Pose ( )
noexcept

Default constructor.

Initializes the pose at position (0,0,0) with neutral orientation (identity quaternion).

Definition at line 14 of file pose_lib.cpp.

15 : position_(Eigen::Vector3d::Zero()), orientation_(Eigen::Quaterniond::Identity())
16{
17}
Eigen::Quaterniond orientation_
Orientation represented as quaternion.
Definition pose_lib.h:314
Eigen::Vector3d position_
Position in 3D space.
Definition pose_lib.h:313

Referenced by inverse(), and operator*().

+ Here is the caller graph for this function:

◆ Pose() [2/8]

MoveG::Pose::Pose ( const Eigen::Vector3d &  position,
const Eigen::Quaterniond &  orientation 
)

Constructor with position and quaternion orientation.

Parameters
positionThe position in space.
orientationThe quaternion representing the orientation.

Definition at line 20 of file pose_lib.cpp.

21 : position_(position),
22 orientation_(orientation.normalized()) // Ensure the quaternion is normalized
23{
24}

◆ Pose() [3/8]

MoveG::Pose::Pose ( const Eigen::Vector3d &  position,
const Eigen::Matrix3d &  rotation_matrix 
)

Constructor with position and rotation matrix.

Parameters
positionThe position in space.
rotation_matrixThe 3x3 rotation matrix.

Definition at line 27 of file pose_lib.cpp.

28 : position_(position), orientation_(Eigen::Quaterniond(rotation_matrix))
29{
30 orientation_.normalize(); // Ensure the quaternion is normalized
31}

References orientation_.

◆ Pose() [4/8]

MoveG::Pose::Pose ( const Eigen::Affine3d &  transformation)
explicit

Constructor with affine transformation.

Parameters
transformationThe 3D affine transformation.

Definition at line 34 of file pose_lib.cpp.

35 : position_(transformation.translation()),
36 orientation_(Eigen::Quaterniond(transformation.rotation()))
37{
38 orientation_.normalize(); // Ensure the quaternion is normalized
39}

References orientation_.

◆ Pose() [5/8]

MoveG::Pose::Pose ( const Eigen::Vector3d &  position,
const Rotation orientation 
)

Constructor with position and Rotation object.

Parameters
positionThe position in space.
orientationThe Rotation object representing the orientation.

Definition at line 42 of file pose_lib.cpp.

43 : position_(position), orientation_(orientation.toQuaternion())
44{
45 orientation_.normalize(); // Ensure the quaternion is normalized
46}

References orientation_.

◆ Pose() [6/8]

MoveG::Pose::Pose ( const Eigen::Matrix4d &  homogeneousT)
explicit

Constructor with homogeneous transformation matrix 4x4.

Parameters
homogeneousTThe 4x4 homogeneous transformation matrix.
Exceptions
std::invalid_argumentIf the matrix is not a valid homogeneous transformation matrix.

Definition at line 49 of file pose_lib.cpp.

50{
51 validateHomogeneousMatrix(homogeneousT);
52
53 // Extract position
54 position_ = homogeneousT.block<3, 1>(0, 3);
55
56 // Extract rotation matrix
57 const Eigen::Matrix3d rotation_matrix = homogeneousT.block<3, 3>(0, 0);
58 orientation_ = Eigen::Quaterniond(rotation_matrix).normalized(); // Ensure normalization
59}
static void validateHomogeneousMatrix(const Eigen::Matrix4d &homogeneousT)
Validates a homogeneous transformation matrix.
Definition pose_lib.cpp:237

References orientation_, position_, and validateHomogeneousMatrix().

+ Here is the call graph for this function:

◆ ~Pose()

MoveG::Pose::~Pose ( )

Destructor.

Definition at line 62 of file pose_lib.cpp.

63{
64 // No dynamic memory to clean up
65}

◆ Pose() [7/8]

MoveG::Pose::Pose ( const Pose other)

Copy constructor.

Parameters
otherThe Pose object to copy.

Definition at line 68 of file pose_lib.cpp.

68 : position_(other.position_), orientation_(other.orientation_)
69{
70}

◆ Pose() [8/8]

MoveG::Pose::Pose ( Pose &&  other)
noexcept

Move constructor.

Parameters
otherThe Pose object to move.

Definition at line 73 of file pose_lib.cpp.

74 : position_(std::move(other.position_)), orientation_(std::move(other.orientation_))
75{
76}

Member Function Documentation

◆ getAffineTransformation()

Eigen::Affine3d MoveG::Pose::getAffineTransformation ( ) const

Gets the affine transformation.

Returns
The 3D affine transformation.

Definition at line 117 of file pose_lib.cpp.

118{
119 Eigen::Affine3d transformation = Eigen::Affine3d::Identity();
120 transformation.translation() = position_;
121 transformation.linear() = orientation_.toRotationMatrix();
122 return transformation;
123}

References orientation_, and position_.

Referenced by main().

+ Here is the caller graph for this function:

◆ getHomogeneousT()

Eigen::Matrix4d MoveG::Pose::getHomogeneousT ( ) const

Gets the homogeneous transformation matrix.

Returns
The 4x4 homogeneous matrix.

Definition at line 125 of file pose_lib.cpp.

126{
127 Eigen::Matrix4d homogeneous = Eigen::Matrix4d::Identity();
128 homogeneous.block<3, 3>(0, 0) = orientation_.toRotationMatrix();
129 homogeneous.block<3, 1>(0, 3) = position_;
130 return homogeneous;
131}

References orientation_, and position_.

Referenced by main().

+ Here is the caller graph for this function:

◆ getPosition()

Eigen::Vector3d MoveG::Pose::getPosition ( ) const

Gets the position.

Returns
The position as a 3D vector.

Definition at line 102 of file pose_lib.cpp.

103{
104 return position_;
105}

References position_.

Referenced by main().

+ Here is the caller graph for this function:

◆ getQuaternion()

Eigen::Quaterniond MoveG::Pose::getQuaternion ( ) const

Gets the orientation quaternion.

Returns
The quaternion representing the orientation.

Definition at line 107 of file pose_lib.cpp.

108{
109 return orientation_;
110}

References orientation_.

Referenced by main().

+ Here is the caller graph for this function:

◆ getQw()

double MoveG::Pose::getQw ( ) const

Gets the W component of the quaternion.

Returns
The W component.

Definition at line 165 of file pose_lib.cpp.

166{
167 return orientation_.w();
168}

References orientation_.

Referenced by main().

+ Here is the caller graph for this function:

◆ getQx()

double MoveG::Pose::getQx ( ) const

Gets the X component of the quaternion.

Returns
The X component.

Definition at line 150 of file pose_lib.cpp.

151{
152 return orientation_.x();
153}

References orientation_.

Referenced by main().

+ Here is the caller graph for this function:

◆ getQy()

double MoveG::Pose::getQy ( ) const

Gets the Y component of the quaternion.

Returns
The Y component.

Definition at line 155 of file pose_lib.cpp.

156{
157 return orientation_.y();
158}

References orientation_.

Referenced by main().

+ Here is the caller graph for this function:

◆ getQz()

double MoveG::Pose::getQz ( ) const

Gets the Z component of the quaternion.

Returns
The Z component.

Definition at line 160 of file pose_lib.cpp.

161{
162 return orientation_.z();
163}

References orientation_.

Referenced by main().

+ Here is the caller graph for this function:

◆ getRotationMatrix()

Eigen::Matrix3d MoveG::Pose::getRotationMatrix ( ) const

Gets the rotation matrix.

Returns
The 3x3 rotation matrix.

Definition at line 112 of file pose_lib.cpp.

113{
114 return orientation_.toRotationMatrix();
115}

References orientation_.

Referenced by main().

+ Here is the caller graph for this function:

◆ getX()

double MoveG::Pose::getX ( ) const

Gets the X coordinate of the position.

Returns
The X coordinate.

Definition at line 135 of file pose_lib.cpp.

136{
137 return position_.x();
138}

References position_.

Referenced by main().

+ Here is the caller graph for this function:

◆ getY()

double MoveG::Pose::getY ( ) const

Gets the Y coordinate of the position.

Returns
The Y coordinate.

Definition at line 140 of file pose_lib.cpp.

141{
142 return position_.y();
143}

References position_.

Referenced by main().

+ Here is the caller graph for this function:

◆ getZ()

double MoveG::Pose::getZ ( ) const

Gets the Z coordinate of the position.

Returns
The Z coordinate.

Definition at line 145 of file pose_lib.cpp.

146{
147 return position_.z();
148}

References position_.

Referenced by main().

+ Here is the caller graph for this function:

◆ globalToLocal()

Eigen::Vector3d MoveG::Pose::globalToLocal ( const Eigen::Vector3d &  global_point) const

Transforms a point from the global frame to the pose's local frame.

Parameters
global_pointThe point in the global coordinate frame.
Returns
The point expressed in the local coordinate frame.

Definition at line 305 of file pose_lib.cpp.

306{
307 // Transform a point from the global coordinate frame to the local frame
308 // This applies the inverse transformation (first translate, then rotate)
309 return orientation_.conjugate() * (global_point - position_);
310}

References orientation_, and position_.

Referenced by main().

+ Here is the caller graph for this function:

◆ inverse()

Pose MoveG::Pose::inverse ( ) const

Calculates the inverse of the pose.

Returns
The inverse pose.

Definition at line 229 of file pose_lib.cpp.

230{
231 const Eigen::Quaterniond inv_orientation = orientation_.conjugate();
232 const Eigen::Vector3d inv_position = -(inv_orientation * position_);
233 return Pose(inv_position, inv_orientation);
234}
Pose() noexcept
Default constructor.
Definition pose_lib.cpp:14

References orientation_, Pose(), and position_.

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ localToGlobal()

Eigen::Vector3d MoveG::Pose::localToGlobal ( const Eigen::Vector3d &  local_point) const

Transforms a point from the pose's local frame to the global frame.

Parameters
local_pointThe point in the local coordinate frame.
Returns
The point expressed in the global coordinate frame.

Definition at line 298 of file pose_lib.cpp.

299{
300 // Transform a point from the local coordinate frame to the global frame
301 // This applies the rotation and then the translation
302 return position_ + orientation_ * local_point;
303}

References orientation_, and position_.

Referenced by main().

+ Here is the caller graph for this function:

◆ operator*()

Pose MoveG::Pose::operator* ( const Pose other) const

Composition of two poses.

Parameters
otherThe second pose to compose.
Returns
A new pose resulting from the composition.

Definition at line 221 of file pose_lib.cpp.

222{
223 const Eigen::Quaterniond combined_orientation = orientation_ * other.orientation_;
224 const Eigen::Vector3d combined_position = position_ + orientation_ * other.position_;
225 return Pose(combined_position, combined_orientation);
226}

References orientation_, Pose(), and position_.

+ Here is the call graph for this function:

◆ operator=() [1/2]

Pose & MoveG::Pose::operator= ( const Pose other)

Copy assignment operator.

Parameters
otherThe Pose object to assign.
Returns
Reference to the assigned object.

Definition at line 79 of file pose_lib.cpp.

80{
81 if (this != &other)
82 {
83 position_ = other.position_;
84 orientation_ = other.orientation_;
85 }
86 return *this;
87}

References orientation_, and position_.

◆ operator=() [2/2]

Pose & MoveG::Pose::operator= ( Pose &&  other)
noexcept

Move assignment operator.

Parameters
otherThe Pose object to move and assign.
Returns
Reference to the assigned object.

Definition at line 90 of file pose_lib.cpp.

91{
92 if (this != &other)
93 {
94 position_ = std::move(other.position_);
95 orientation_ = std::move(other.orientation_);
96 }
97 return *this;
98}

◆ orientationDistance()

double MoveG::Pose::orientationDistance ( const Pose other) const

Calculates the angular distance between the orientations of two poses.

Parameters
otherThe pose to calculate the angular distance with.
Returns
The angular distance in radians.

Definition at line 211 of file pose_lib.cpp.

212{
213 // Compute the angle between quaternions
214 double dot = std::abs(orientation_.dot(other.orientation_));
215 // Clamp dot to [-1, 1] to avoid numerical issues
216 dot = std::max(-1.0, std::min(1.0, dot));
217 return 2.0 * std::acos(dot);
218}

References orientation_.

Referenced by main().

+ Here is the caller graph for this function:

◆ positionDistance()

double MoveG::Pose::positionDistance ( const Pose other) const

Calculates the Euclidean distance between the positions of two poses.

Parameters
otherThe pose to calculate the distance with.
Returns
The Euclidean distance between the positions.

Definition at line 206 of file pose_lib.cpp.

207{
208 return (position_ - other.position_).norm();
209}

References position_.

Referenced by main().

+ Here is the caller graph for this function:

◆ setAffineTransformation()

void MoveG::Pose::setAffineTransformation ( const Eigen::Affine3d &  transformation)

Sets the affine transformation.

Parameters
transformationThe new 3D affine transformation.

Definition at line 187 of file pose_lib.cpp.

188{
189 position_ = transformation.translation();
190 orientation_ = Eigen::Quaterniond(transformation.rotation()).normalized();
191}

References orientation_, and position_.

◆ setHomogeneousT()

void MoveG::Pose::setHomogeneousT ( const Eigen::Matrix4d &  homogeneousT)

Sets the homogeneous transformation matrix.

Parameters
homogeneousTThe new 4x4 homogeneous matrix.
Exceptions
std::invalid_argumentIf the matrix is not a valid homogeneous transformation matrix.

Definition at line 193 of file pose_lib.cpp.

194{
195 validateHomogeneousMatrix(homogeneousT);
196
197 // Extract position
198 position_ = homogeneousT.block<3, 1>(0, 3);
199
200 // Extract rotation matrix
201 const Eigen::Matrix3d rotation_matrix = homogeneousT.block<3, 3>(0, 0);
202 orientation_ = Eigen::Quaterniond(rotation_matrix).normalized();
203}

References orientation_, position_, and validateHomogeneousMatrix().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setOrientation()

void MoveG::Pose::setOrientation ( const Eigen::Quaterniond &  orientation)

Sets the orientation via quaternion.

Parameters
orientationThe new quaternion representing the orientation.

Definition at line 177 of file pose_lib.cpp.

178{
179 orientation_ = orientation.normalized(); // Ensure the quaternion is normalized
180}

References orientation_.

Referenced by main().

+ Here is the caller graph for this function:

◆ setPosition()

void MoveG::Pose::setPosition ( const Eigen::Vector3d &  position)

Sets the position.

Parameters
positionThe new position as a 3D vector.

Definition at line 172 of file pose_lib.cpp.

173{
174 position_ = position;
175}

References position_.

Referenced by main().

+ Here is the caller graph for this function:

◆ setRotationMatrix()

void MoveG::Pose::setRotationMatrix ( const Eigen::Matrix3d &  rotation_matrix)

Sets the rotation matrix.

Parameters
rotation_matrixThe new 3x3 rotation matrix.

Definition at line 182 of file pose_lib.cpp.

183{
184 orientation_ = Eigen::Quaterniond(rotation_matrix).normalized(); // Ensure normalization
185}

References orientation_.

Referenced by main().

+ Here is the caller graph for this function:

◆ transformPose()

Pose MoveG::Pose::transformPose ( const Pose transform) const

Transforms this pose from one coordinate frame to another.

Parameters
transformThe transformation between the two coordinate frames.
Returns
A new pose expressed in the target coordinate frame.

Definition at line 291 of file pose_lib.cpp.

292{
293 // This method transforms this pose by the given transformation
294 // This is useful for changing coordinate frames
295 return transform * (*this);
296}

Referenced by main().

+ Here is the caller graph for this function:

◆ validateHomogeneousMatrix()

void MoveG::Pose::validateHomogeneousMatrix ( const Eigen::Matrix4d &  homogeneousT)
staticprivate

Validates a homogeneous transformation matrix.

Checks that the last row is [0,0,0,1] and that the rotation part is orthogonal.

Parameters
homogeneousTThe homogeneous transformation matrix to validate.
Exceptions
std::invalid_argumentIf the matrix is not a valid homogeneous transformation matrix.

Definition at line 237 of file pose_lib.cpp.

238{
239 // Check the last row
240 Eigen::RowVector4d expected_last_row(0, 0, 0, 1);
241 Eigen::RowVector4d actual_last_row = homogeneousT.block<1, 4>(3, 0);
242
243 if (!actual_last_row.isApprox(expected_last_row, 1e-6))
244 {
245 std::stringstream error_msg;
246 error_msg << "Invalid homogeneous transformation matrix. The last row must be [0, 0, 0, "
247 "1], but got ["
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());
251 }
252
253 // Extract the rotation matrix part
254 const Eigen::Matrix3d rotation_part = homogeneousT.block<3, 3>(0, 0);
255
256 // Check if the rotation matrix is orthogonal
257 // A rotation matrix multiplied by its transpose should give the identity matrix
258 Eigen::Matrix3d orthogonality_check = rotation_part * rotation_part.transpose();
259 Eigen::Matrix3d identity = Eigen::Matrix3d::Identity();
260
261 if (!orthogonality_check.isApprox(identity, 1e-6))
262 {
263 std::stringstream error_msg;
264 error_msg
265 << "Invalid homogeneous transformation matrix. The rotation part is not orthogonal.";
266 throw std::invalid_argument(error_msg.str());
267 }
268
269 // Additionally, check the determinant is approximately 1 (proper rotation)
270 double det = rotation_part.determinant();
271 if (std::abs(det - 1.0) > 1e-6)
272 {
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());
277 }
278}

Referenced by Pose(), and setHomogeneousT().

+ Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
const Pose pose 
)
friend

Overloads the stream insertion operator.

Parameters
osThe output stream.
poseThe Pose object to insert into the stream.
Returns
Reference to the output stream.

Definition at line 281 of file pose_lib.cpp.

282{
283 os << "Position: [" << pose.position_.x() << ", " << pose.position_.y() << ", "
284 << pose.position_.z() << "]\n";
285 os << "Orientation (quaternion): [" << pose.orientation_.x() << ", " << pose.orientation_.y()
286 << ", " << pose.orientation_.z() << ", " << pose.orientation_.w() << "]";
287 return os;
288}

Member Data Documentation

◆ orientation_

◆ position_


The documentation for this class was generated from the following files: