template class mrpt::poses::CPoseOrPoint
Overview
The base template class for 2D & 3D points and poses.
This class use the Curiously Recurring Template Pattern (CRTP) to define a set of common methods to all the children classes without the cost of virtual methods. Since most important methods are inline, they will be expanded at compile time and optimized for every specific derived case.
For more information and examples, refer to the 2D/3D Geometry tutorial online.
Introduction to 2D and 3D representation classes
There are two class of spatial representation classes:
Point: A point in the common mathematical sense, with no directional information.
2D: A 2D point is represented just by its coordinates (x,y).
3D: A 3D point is represented by its coordinates (x,y,z).
Pose: It is a point, plus a direction.
2D: A 2D pose is a 2D point plus a single angle, the yaw or φ angle: the angle from the positive X angle.
3D: A 3D point is a 3D point plus three orientation angles (More details above).
In the case for a 3D orientation many representation angles can be used (Euler angles,yaw/pitch/roll,…) but all of them can be handled by a 4x4 matrix called “Homogeneous Matrix”. This matrix includes both, the translation and the orientation for a point or a pose, and it can be obtained using the method getHomogeneousMatrix() which is defined for any pose or point. Note that when the YPR angles are used to define a 3D orientation, these three values can not be extracted from the matrix again.
Homogeneous matrices: These are 4x4 matrices which can represent any translation or rotation in 2D & 3D. See the tutorial online for more details. *
Operators: There are operators defined for the pose compounding \(\oplus\) and inverse pose compounding \(\ominus\) of poses and points. For example, let “a” and “b” be 2D or 3D poses. Then “a+b” returns the resulting pose of “moving b” from “a”; and “b-a” returns the pose of “b” as it is seen “from a”. They can be mixed points and poses, being 2D or 3D, in these operators, with the following results:
Does "a+b" return a Pose or a Point?
+---------------------------------+
| a \ b | Pose | Point |
+----------+-----------+----------+
| Pose | Pose | Point |
| Point | Pose | Point |
+---------------------------------+
Does "a-b" return a Pose or a Point?
+---------------------------------+
| a \ b | Pose | Point |
+----------+-----------+----------+
| Pose | Pose | Pose |
| Point | Point | Point |
+---------------------------------+
Does "a+b" and "a-b" return a 2D or 3D object?
+-------------------------+
| a \ b | 2D | 3D |
+----------+--------------+
| 2D | 2D | 3D |
| 3D | 3D | 3D |
+-------------------------+
See also:
#include <mrpt/poses/CPoseOrPoint.h> template <class DERIVEDCLASS, std::size_t DIM> class CPoseOrPoint: public mrpt::poses::detail:: pose_point_impl< DERIVEDCLASS, mrpt::poses::detail::T3DTypeHelper< DERIVEDCLASS >::is_3D_val > { public: // typedefs typedef mrpt::math::CVectorFixedDouble<static_cast<mrpt::math::matrix_dim_t>(DIM)> vector_t; // construction CPoseOrPoint(const CPoseOrPoint&); CPoseOrPoint(CPoseOrPoint&&); // methods double x() const; double y() const; double& x(); double& y(); void x(const double v); void y(const double v); void x_incr(const double v); void y_incr(const double v); template <class OTHERCLASS, std::size_t DIM2> double sqrDistanceTo(const CPoseOrPoint<OTHERCLASS, DIM2>& b) const; template <class OTHERCLASS, std::size_t DIM2> double distanceTo(const CPoseOrPoint<OTHERCLASS, DIM2>& b) const; double distance2DToSquare(double ax, double ay) const; double distance3DToSquare(double ax, double ay, double az) const; double distance2DTo(double ax, double ay) const; double distance3DTo(double ax, double ay, double az) const; double distanceTo(const mrpt::math::TPoint3D& b) const; double norm() const; vector_t asVectorVal() const; template <class MATRIX44> MATRIX44 getHomogeneousMatrixVal() const; template <class MATRIX44> void getInverseHomogeneousMatrix(MATRIX44& out_HM) const; template <class MATRIX44> MATRIX44 getInverseHomogeneousMatrixVal() const; static bool is3DPoseOrPoint(); CPoseOrPoint& operator = (const CPoseOrPoint&); CPoseOrPoint& operator = (CPoseOrPoint&&); const DERIVEDCLASS& derived() const; DERIVEDCLASS& derived(); }; // direct descendants template <class DERIVEDCLASS, std::size_t DIM> class CPoint; template <class DERIVEDCLASS, std::size_t DIM> class CPose;
Typedefs
typedef mrpt::math::CVectorFixedDouble<static_cast<mrpt::math::matrix_dim_t>(DIM)> vector_t
Fixed-size vector of the correct size to hold all the coordinates of the point/pose.
Methods
double x() const
Common members of all points & poses classes.
< Get X coord.
double y() const
< Get Y coord.
template <class OTHERCLASS, std::size_t DIM2> double sqrDistanceTo(const CPoseOrPoint<OTHERCLASS, DIM2>& b) const
Returns the squared euclidean distance to another pose/point:
template <class OTHERCLASS, std::size_t DIM2> double distanceTo(const CPoseOrPoint<OTHERCLASS, DIM2>& b) const
Returns the Euclidean distance to another pose/point:
double distance2DToSquare(double ax, double ay) const
Returns the squared 2D distance from this pose/point to a 2D point (ignores Z, if it exists).
double distance3DToSquare(double ax, double ay, double az) const
Returns the squared 3D distance from this pose/point to a 3D point.
double distance2DTo(double ax, double ay) const
Returns the 2D distance from this pose/point to a 2D point (ignores Z, if it exists).
double distance3DTo(double ax, double ay, double az) const
Returns the 3D distance from this pose/point to a 3D point.
double distanceTo(const mrpt::math::TPoint3D& b) const
Returns the euclidean distance to a 3D point:
double norm() const
Returns the euclidean norm of vector: \(||\mathbf{x}|| = \sqrt{x^2+y^2+z^2}\).
vector_t asVectorVal() const
Return the pose or point as a 1xN vector with all the components (see derived classes for each implementation)
template <class MATRIX44> MATRIX44 getHomogeneousMatrixVal() const
Returns the corresponding 4x4 homogeneous transformation matrix for the point(translation) or pose (translation+orientation).
See also:
template <class MATRIX44> void getInverseHomogeneousMatrix(MATRIX44& out_HM) const
Returns the corresponding 4x4 inverse homogeneous transformation matrix for this point or pose.
See also:
getHomogeneousMatrix
template <class MATRIX44> MATRIX44 getInverseHomogeneousMatrixVal() const
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
static bool is3DPoseOrPoint()
Return true for poses or points with a Z component, false otherwise.