Lightweight SE(2)/SE(3) types, geometry functions.
Overview
Lightweight SE(2)/SE(3) data types, geometry functions, etc.
The “lightweight” adjective is used here in contrast to classes derived from mrpt::poses::CPoseOrPoint. The “lightweight” alternative types here, defined in mrpt::math, are simple C++ structures without special memory alignment requirements and without a deep hiearchy of class inheritance, as the “heavier” classes in mrpt::poses have. In turn, the latter ones offer:
Serialization (see: [mrpt-serialization])
Buffered trigronometric calculations (e.g. mrpt::poses::CPose3D), hence they will be preferred to lightweight alternaives (e.g. mrpt::math::TPose3D) if the same pose is to be used over and over again to transform multiple points/poses.
See list of classes below.
// typedefs typedef TBoundingBox_<double> mrpt::math::TBoundingBox; typedef TBoundingBox_<float> mrpt::math::TBoundingBoxf; typedef TOrientedBox_<double> mrpt::math::TOrientedBox; typedef TOrientedBox_<float> mrpt::math::TOrientedBoxf; typedef TPlane mrpt::math::TPlane3D; typedef TPoint2D_<double> mrpt::math::TPoint2D; typedef TPoint2D_<float> mrpt::math::TPoint2Df; typedef TPoint2D mrpt::math::TVector2D; typedef TPoint2Df mrpt::math::TVector2Df; typedef TPoint3D_<double> mrpt::math::TPoint3D; typedef TPoint3D_<float> mrpt::math::TPoint3Df; typedef TPoint3D mrpt::math::TVector3D; typedef TPoint3Df mrpt::math::TVector3Df; // structs template <typename Derived> struct mrpt::math::internal::ProvideStaticResize; template <typename Derived> struct mrpt::math::internal::ProvidesStringConversion; template <typename T> struct mrpt::math::TBoundingBox_; struct mrpt::math::TLine2D; struct mrpt::math::TLine3D; struct mrpt::math::TObject2D; struct mrpt::math::TObject3D; struct mrpt::math::TPlane; template <typename T> struct mrpt::math::TPoint2D_; template <typename T> struct mrpt::math::TPoint2D_data; template <typename T> struct mrpt::math::TPoint3D_; template <typename T> struct mrpt::math::TPoint3D_data; struct mrpt::math::TPointXYZIu8; struct mrpt::math::TPointXYZRGBAf; struct mrpt::math::TPointXYZRGBu8; struct mrpt::math::TPointXYZfIu8; struct mrpt::math::TPointXYZfRGBAu8; struct mrpt::math::TPointXYZfRGBu8; struct mrpt::math::TPose2D; struct mrpt::math::TPose3D; struct mrpt::math::TPose3DQuat; struct mrpt::math::TPoseOrPoint; struct mrpt::math::TSegment2D; struct mrpt::math::TSegment3D; struct mrpt::math::TTwist2D; struct mrpt::math::TTwist3D; // classes class mrpt::math::CPolygon; template <typename T> class mrpt::math::TOrientedBox_; class mrpt::math::TPolygon2D; class mrpt::math::TPolygon3D; class mrpt::math::TPolygonWithPlane; // global functions bool mrpt::math::intersect(const TSegment3D& s1, const TSegment3D& s2, TObject3D& obj); bool mrpt::math::intersect(const TSegment3D& s1, const TPlane& p2, TObject3D& obj); bool mrpt::math::intersect(const TSegment3D& s1, const TLine3D& r2, TObject3D& obj); bool mrpt::math::intersect(const TPlane& p1, const TSegment3D& s2, TObject3D& obj); bool mrpt::math::intersect(const TPlane& p1, const TPlane& p2, TObject3D& obj); bool mrpt::math::intersect(const TPlane& p1, const TLine3D& p2, TObject3D& obj); bool mrpt::math::intersect(const TLine3D& r1, const TSegment3D& s2, TObject3D& obj); bool mrpt::math::intersect(const TLine3D& r1, const TPlane& p2, TObject3D& obj); bool mrpt::math::intersect(const TLine3D& r1, const TLine3D& r2, TObject3D& obj); bool mrpt::math::intersect(const TLine2D& r1, const TLine2D& r2, TObject2D& obj); bool mrpt::math::intersect(const TLine2D& r1, const TSegment2D& s2, TObject2D& obj); bool mrpt::math::intersect(const TSegment2D& s1, const TLine2D& r2, TObject2D& obj); bool mrpt::math::intersect(const TSegment2D& s1, const TSegment2D& s2, TObject2D& obj); double mrpt::math::getAngle(const TPlane& p1, const TPlane& p2); double mrpt::math::getAngle(const TPlane& p1, const TLine3D& r2); double mrpt::math::getAngle(const TLine3D& r1, const TPlane& p2); double mrpt::math::getAngle(const TLine3D& r1, const TLine3D& r2); double mrpt::math::getAngle(const TLine2D& r1, const TLine2D& r2); template <typename T> void mrpt::math::slerp( const CQuaternion<T>& q0, const CQuaternion<T>& q1, const double t, CQuaternion<T>& q ); void mrpt::math::slerp(const TPose3D& q0, const TPose3D& q1, const double t, TPose3D& p); void mrpt::math::slerp_ypr( const mrpt::math::TPose3D& q0, const mrpt::math::TPose3D& q1, const double t, mrpt::math::TPose3D& p ); mrpt::serialization::CArchive& mrpt::math::operator >> ( mrpt::serialization::CArchive& in, mrpt::math::TBoundingBoxf& bb ); mrpt::serialization::CArchive& mrpt::math::operator << ( mrpt::serialization::CArchive& out, const mrpt::math::TBoundingBoxf& bb ); mrpt::serialization::CArchive& mrpt::math::operator >> ( mrpt::serialization::CArchive& in, mrpt::math::TBoundingBox& bb ); mrpt::serialization::CArchive& mrpt::math::operator << ( mrpt::serialization::CArchive& out, const mrpt::math::TBoundingBox& bb ); mrpt::serialization::CArchive& mrpt::math::operator >> ( mrpt::serialization::CArchive& in, mrpt::math::TLine2D& l ); mrpt::serialization::CArchive& mrpt::math::operator << ( mrpt::serialization::CArchive& out, const mrpt::math::TLine2D& l ); std::ostream& mrpt::math::operator << (std::ostream& o, const TLine2D& p); mrpt::serialization::CArchive& mrpt::math::operator >> ( mrpt::serialization::CArchive& in, mrpt::math::TLine3D& l ); mrpt::serialization::CArchive& mrpt::math::operator << ( mrpt::serialization::CArchive& out, const mrpt::math::TLine3D& l ); std::ostream& mrpt::math::operator << (std::ostream& o, const TLine3D& p); mrpt::serialization::CArchive& mrpt::math::operator >> ( mrpt::serialization::CArchive& in, mrpt::math::TObject2D& o ); mrpt::serialization::CArchive& mrpt::math::operator << ( mrpt::serialization::CArchive& out, const mrpt::math::TObject2D& o ); std::ostream& mrpt::math::operator << (std::ostream& o, const mrpt::math::TObject2D& obj); mrpt::serialization::CArchive& mrpt::math::operator >> ( mrpt::serialization::CArchive& in, mrpt::math::TObject3D& o ); mrpt::serialization::CArchive& mrpt::math::operator << ( mrpt::serialization::CArchive& out, const mrpt::math::TObject3D& o ); std::ostream& mrpt::math::operator << (std::ostream& o, const mrpt::math::TObject3D& obj); mrpt::serialization::CArchive& mrpt::math::operator >> ( mrpt::serialization::CArchive& in, mrpt::math::TOrientedBox& bb ); mrpt::serialization::CArchive& mrpt::math::operator << ( mrpt::serialization::CArchive& out, const mrpt::math::TOrientedBox& bb ); mrpt::serialization::CArchive& mrpt::math::operator >> ( mrpt::serialization::CArchive& in, mrpt::math::TOrientedBoxf& bb ); mrpt::serialization::CArchive& mrpt::math::operator << ( mrpt::serialization::CArchive& out, const mrpt::math::TOrientedBoxf& bb ); mrpt::serialization::CArchive& mrpt::math::operator >> ( mrpt::serialization::CArchive& in, mrpt::math::TPlane& p ); mrpt::serialization::CArchive& mrpt::math::operator << ( mrpt::serialization::CArchive& out, const mrpt::math::TPlane& p ); std::ostream& mrpt::math::operator << (std::ostream& o, const TPlane& p); template <typename T> constexpr TPoint2D_<T> mrpt::math::operator - (const TPoint2D_<T>& p1); template < typename T, typename Scalar, std::enable_if_t<std::is_convertible_v<Scalar, T>>* = nullptr > constexpr TPoint2D_<T> mrpt::math::operator * ( const Scalar scalar, const TPoint2D_<T>& p ); template <typename T> constexpr bool mrpt::math::operator == (const TPoint2D_<T>& p1, const TPoint2D_<T>& p2); template <typename T> constexpr bool mrpt::math::operator != (const TPoint2D_<T>& p1, const TPoint2D_<T>& p2); mrpt::serialization::CArchive& mrpt::math::operator >> ( mrpt::serialization::CArchive& in, mrpt::math::TPointXYZfRGBu8& p ); mrpt::serialization::CArchive& mrpt::math::operator << ( mrpt::serialization::CArchive& out, const mrpt::math::TPointXYZfRGBu8& p ); mrpt::serialization::CArchive& mrpt::math::operator >> ( mrpt::serialization::CArchive& in, mrpt::math::TPointXYZfRGBAu8& p ); mrpt::serialization::CArchive& mrpt::math::operator << ( mrpt::serialization::CArchive& out, const mrpt::math::TPointXYZfRGBAu8& p ); template <typename T> constexpr TPoint3D_<T> mrpt::math::operator - (const TPoint3D_<T>& p1); template < typename T, typename Scalar, std::enable_if_t<std::is_convertible_v<Scalar, T>>* = nullptr > constexpr TPoint3D_<T> mrpt::math::operator * ( const Scalar scalar, const TPoint3D_<T>& p ); template <typename T> constexpr bool mrpt::math::operator == (const TPoint3D_<T>& p1, const TPoint3D_<T>& p2); template <typename T> constexpr bool mrpt::math::operator != (const TPoint3D_<T>& p1, const TPoint3D_<T>& p2); template < class PoseOrPoint, typename = std::enable_if_t<std::is_base_of_v<mrpt::math::TPoseOrPoint, PoseOrPoint>> > std::ostream& mrpt::math::operator << ( std::ostream& o, const PoseOrPoint& p ); template < class PoseOrPoint, typename = std::enable_if_t<std::is_base_of_v<mrpt::math::TPoseOrPoint, PoseOrPoint>> > mrpt::serialization::CArchive& mrpt::math::operator >> ( mrpt::serialization::CArchive& in, PoseOrPoint& o ); template < class PoseOrPoint, typename = std::enable_if_t<std::is_base_of_v<mrpt::math::TPoseOrPoint, PoseOrPoint>> > mrpt::serialization::CArchive& mrpt::math::operator << ( mrpt::serialization::CArchive& out, const PoseOrPoint& o );
Typedefs
typedef TBoundingBox_<double> mrpt::math::TBoundingBox
A bounding box defined by the 3D points at each minimum-maximum corner.
See also:
mrpt::math::TPoint3D, mrpt::math::TPoint3Df
typedef TOrientedBox_<double> mrpt::math::TOrientedBox
3D oriented bounding box, defined by dimensions and pose
See also:
typedef TPoint2D_<double> mrpt::math::TPoint2D
Lightweight 2D point / free vector in R^2 (double precision).
Coordinate access via x, y members or operator[] (index 0→x, 1→y).
See also:
mrpt::poses::CPoint2D, TPoint2Df, TVector2D
typedef TPoint2D_<float> mrpt::math::TPoint2Df
Single-precision variant of TPoint2D.
typedef TPoint2D mrpt::math::TVector2D
Type alias for a 2D free vector (same storage as TPoint2D; use this name when the object represents a direction or displacement rather than a position).
typedef TPoint2Df mrpt::math::TVector2Df
Single-precision variant of TVector2D.
typedef TPoint3D_<double> mrpt::math::TPoint3D
Lightweight 3D point / free vector in R^3 (double precision).
Coordinate access via x, y, z members or operator[] (index 0→x, 1→y, 2→z). Memory layout: 1-byte packed, no padding — safe for direct memcpy / mmap with point clouds.
See also:
mrpt::poses::CPoint3D, TPoint3Df, TVector3D
typedef TPoint3D_<float> mrpt::math::TPoint3Df
Single-precision variant of TPoint3D.
typedef TPoint3D mrpt::math::TVector3D
Type alias for a 3D free vector (same storage as TPoint3D; use this name when the object represents a direction, velocity, or displacement rather than a position).
typedef TPoint3Df mrpt::math::TVector3Df
Single-precision variant of TVector3D.
Global Functions
bool mrpt::math::intersect(const TSegment3D& s1, const TSegment3D& s2, TObject3D& obj)
Gets the intersection between two 3D segments.
Possible outcomes:
Segments intersect: Return=true, obj.getType()= GeometricEntity::POINT
Segments don’t intersect & are parallel: Return=true, obj.getType()= GeometricEntity::SEGMENT, obj is the segment “in between” both segments.
Segments don’t intersect & aren’t parallel: Return=false.
See also:
bool mrpt::math::intersect(const TSegment3D& s1, const TPlane& p2, TObject3D& obj)
Gets the intersection between a 3D segment and a plane.
Possible outcomes:
Don’t intersect: Return=false
s1 is within the plane: Return=true, obj.getType()= GeometricEntity::SEGMENT
s1 intersects the plane at one point: Return=true, obj.getType()= GeometricEntity::POINT
See also:
bool mrpt::math::intersect(const TSegment3D& s1, const TLine3D& r2, TObject3D& obj)
Gets the intersection between a 3D segment and a 3D line.
Possible outcomes:
They don’t intersect : Return=false
s1 lies within the line: Return=true, obj.getType()= GeometricEntity::SEGMENT
s1 intersects the line at a point: Return=true, obj.getType()= GeometricEntity::POINT
See also:
bool mrpt::math::intersect(const TPlane& p1, const TSegment3D& s2, TObject3D& obj)
Gets the intersection between a plane and a 3D segment.
Possible outcomes:
Don’t intersect: Return=false
s2 is within the plane: Return=true, obj.getType()= GeometricEntity::SEGMENT
s2 intersects the plane at one point: Return=true, obj.getType()= GeometricEntity::POINT
See also:
bool mrpt::math::intersect(const TPlane& p1, const TPlane& p2, TObject3D& obj)
Gets the intersection between two planes.
Possible outcomes:
Planes are parallel: Return=false
Planes intersect into a line: Return=true, obj.getType()= GeometricEntity::LINE
See also:
bool mrpt::math::intersect(const TPlane& p1, const TLine3D& p2, TObject3D& obj)
Gets the intersection between a plane and a 3D line.
Possible outcomes:
Line is parallel to plane but not within it: Return=false
Line is contained in the plane: Return=true, obj.getType()= GeometricEntity::LINE
Line intersects the plane at one point: Return=true, obj.getType()= GeometricEntity::POINT
See also:
bool mrpt::math::intersect(const TLine3D& r1, const TSegment3D& s2, TObject3D& obj)
Gets the intersection between a 3D line and a 3D segment.
Possible outcomes:
They don’t intersect : Return=false
s2 lies within the line: Return=true, obj.getType()= GeometricEntity::SEGMENT
s2 intersects the line at a point: Return=true, obj.getType()= GeometricEntity::POINT
See also:
bool mrpt::math::intersect(const TLine3D& r1, const TPlane& p2, TObject3D& obj)
Gets the intersection between a 3D line and a plane.
Possible outcomes:
Line is parallel to plane but not within it: Return=false
Line is contained in the plane: Return=true, obj.getType()= GeometricEntity::LINE
Line intersects the plane at one point: Return=true, obj.getType()= GeometricEntity::POINT
See also:
bool mrpt::math::intersect(const TLine3D& r1, const TLine3D& r2, TObject3D& obj)
Gets the intersection between two 3D lines.
Possible outcomes:
Lines do not intersect: Return=false
Lines are parallel and do not coincide: Return=false
Lines coincide (are the same): Return=true, obj.getType()= GeometricEntity::LINE
Lines intesect in a point: Return=true, obj.getType()= GeometricEntity::POINT
See also:
bool mrpt::math::intersect(const TLine2D& r1, const TLine2D& r2, TObject2D& obj)
Gets the intersection between two 2D lines.
Possible outcomes:
Lines do not intersect: Return=false
Lines are parallel and do not coincide: Return=false
Lines coincide (are the same): Return=true, obj.getType()= GeometricEntity::LINE
Lines intesect in a point: Return=true, obj.getType()= GeometricEntity::POINT
See also:
bool mrpt::math::intersect(const TLine2D& r1, const TSegment2D& s2, TObject2D& obj)
Gets the intersection between a 2D line and a 2D segment.
Possible outcomes:
They don’t intersect: Return=false
s2 lies within the line: Return=true, obj.getType()= GeometricEntity::SEGMENT
Both intersects in one point: Return=true, obj.getType()= GeometricEntity::POINT
See also:
bool mrpt::math::intersect(const TSegment2D& s1, const TLine2D& r2, TObject2D& obj)
Gets the intersection between a 2D line and a 2D segment.
Possible outcomes:
They don’t intersect: Return=false
s1 lies within the line: Return=true, obj.getType()= GeometricEntity::SEGMENT
Both intersects in one point: Return=true, obj.getType()= GeometricEntity::POINT
See also:
bool mrpt::math::intersect(const TSegment2D& s1, const TSegment2D& s2, TObject2D& obj)
Gets the intersection between two 2D segments.
Possible outcomes:
Segments intersect: Return=true, obj.getType()= GeometricEntity::POINT
Segments don’t intersect & are parallel: Return=true, obj.getType()= GeometricEntity::SEGMENT, obj is the segment “in between” both segments.
Segments don’t intersect & aren’t parallel: Return=false.
See also:
double mrpt::math::getAngle(const TPlane& p1, const TPlane& p2)
Computes the angle between two planes.
double mrpt::math::getAngle(const TPlane& p1, const TLine3D& r2)
Computes the angle between a plane and a 3D line or segment (implicit constructor will be used if passing a segment instead of a line).
double mrpt::math::getAngle(const TLine3D& r1, const TPlane& p2)
Computes the angle between a 3D line or segment and a plane (implicit constructor will be used if passing a segment instead of a line).
double mrpt::math::getAngle(const TLine3D& r1, const TLine3D& r2)
Computes the accute relative angle (range: [-PI/2,PI/2]) between two lines.
Implicit constructor allows passing a segment as argument too.
double mrpt::math::getAngle(const TLine2D& r1, const TLine2D& r2)
Computes the relative angle (range: [-PI,PI]) of line 2 wrt line 1.
Implicit constructor allows passing a segment as argument too.
template <typename T> void mrpt::math::slerp( const CQuaternion<T>& q0, const CQuaternion<T>& q1, const double t, CQuaternion<T>& q )
SLERP interpolation between two quaternions.
Parameters:
q0 |
The quaternion for t=0 |
q1 |
The quaternion for t=1 |
t |
A “time” parameter, in the range [0,1]. |
q |
The output, interpolated quaternion. |
T |
The type of the quaternion (e.g. float, double). |
std::exception |
Only in Debug, if t is not in the valid range. |
See also:
http://en.wikipedia.org/wiki/Slerp
void mrpt::math::slerp(const TPose3D& q0, const TPose3D& q1, const double t, TPose3D& p)
SLERP interpolation between two 6D poses - like mrpt::math::slerp for quaternions, but interpolates the [X,Y,Z] coordinates as well.
Parameters:
p0 |
The pose for t=0 |
p1 |
The pose for t=1 |
t |
A “time” parameter, in the range [0,1]. |
p |
The output, interpolated pose. |
std::exception |
Only in Debug, if t is not in the valid range. |
std::ostream& mrpt::math::operator << (std::ostream& o, const TLine2D& p)
Text streaming function.
std::ostream& mrpt::math::operator << (std::ostream& o, const TLine3D& p)
Text streaming function.
std::ostream& mrpt::math::operator << (std::ostream& o, const mrpt::math::TObject2D& obj)
Textual print stream operator.
See also:
std::ostream& mrpt::math::operator << (std::ostream& o, const mrpt::math::TObject3D& obj)
Textual print stream operator.
See also:
std::ostream& mrpt::math::operator << (std::ostream& o, const TPlane& p)
Text streaming function.
template <typename T> constexpr TPoint2D_<T> mrpt::math::operator - (const TPoint2D_<T>& p1)
Unary minus operator for 2D points/vectors.
template < typename T, typename Scalar, std::enable_if_t<std::is_convertible_v<Scalar, T>>* = nullptr > constexpr TPoint2D_<T> mrpt::math::operator * ( const Scalar scalar, const TPoint2D_<T>& p )
scalar times vector operator.
template <typename T> constexpr bool mrpt::math::operator == ( const TPoint2D_<T>& p1, const TPoint2D_<T>& p2 )
Exact comparison between 2D points.
template <typename T> constexpr bool mrpt::math::operator != ( const TPoint2D_<T>& p1, const TPoint2D_<T>& p2 )
Exact comparison between 2D points.
template <typename T> constexpr TPoint3D_<T> mrpt::math::operator - (const TPoint3D_<T>& p1)
Unary minus operator for 3D points/vectors.
template < typename T, typename Scalar, std::enable_if_t<std::is_convertible_v<Scalar, T>>* = nullptr > constexpr TPoint3D_<T> mrpt::math::operator * ( const Scalar scalar, const TPoint3D_<T>& p )
scalar times vector operator.
template <typename T> constexpr bool mrpt::math::operator == ( const TPoint3D_<T>& p1, const TPoint3D_<T>& p2 )
Exact comparison between 3D points.
template <typename T> constexpr bool mrpt::math::operator != ( const TPoint3D_<T>& p1, const TPoint3D_<T>& p2 )
Exact comparison between 3D points.
template < class PoseOrPoint, typename = std::enable_if_t<std::is_base_of_v<mrpt::math::TPoseOrPoint, PoseOrPoint>> > std::ostream& mrpt::math::operator << ( std::ostream& o, const PoseOrPoint& p )
Text streaming function.
template < class PoseOrPoint, typename = std::enable_if_t<std::is_base_of_v<mrpt::math::TPoseOrPoint, PoseOrPoint>> > mrpt::serialization::CArchive& mrpt::math::operator >> ( mrpt::serialization::CArchive& in, PoseOrPoint& o )
Binary streaming function.
template < class PoseOrPoint, typename = std::enable_if_t<std::is_base_of_v<mrpt::math::TPoseOrPoint, PoseOrPoint>> > mrpt::serialization::CArchive& mrpt::math::operator << ( mrpt::serialization::CArchive& out, const PoseOrPoint& o )
Binary streaming function.