MRPT  2.0.4
TSegment3D.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
11 #include <mrpt/math/TPoint3D.h>
12 #include <mrpt/math/TPoseOrPoint.h>
13 #include <mrpt/math/TSegment2D.h>
14 
15 namespace mrpt::math
16 {
17 /** 3D segment, consisting of two points.
18  * \sa TSegment2D,TLine3D,TPlane,TPolygon3D,TPoint3D
19  */
20 struct TSegment3D
21 {
22  public:
23  TPoint3D point1; //!< origin point
24  TPoint3D point2; //!< final point
25 
26  /** Segment length */
27  double length() const;
28 
29  /** Distance to point */
30  double distance(const TPoint3D& point) const;
31 
32  /** Distance to another segment */
33  double distance(const TSegment3D& segment) const;
34  /**
35  * Check whether a point is inside the segment.
36  */
37  bool contains(const TPoint3D& point) const;
38  /** Access to points using operator[0-1] */
39  TPoint3D& operator[](size_t i)
40  {
41  switch (i)
42  {
43  case 0:
44  return point1;
45  case 1:
46  return point2;
47  default:
48  throw std::out_of_range("index out of range");
49  }
50  }
51  /** Access to points using operator[0-1] */
52  const TPoint3D& operator[](size_t i) const
53  {
54  switch (i)
55  {
56  case 0:
57  return point1;
58  case 1:
59  return point2;
60  default:
61  throw std::out_of_range("index out of range");
62  }
63  }
64  /**
65  * Projection into 2D space, discarding the z.
66  */
67  void generate2DObject(TSegment2D& s) const;
68  /**
69  * Segment's central point.
70  */
71  void getCenter(TPoint3D& p) const
72  {
73  p.x = (point1.x + point2.x) / 2;
74  p.y = (point1.y + point2.y) / 2;
75  p.z = (point1.z + point2.z) / 2;
76  }
77  /**
78  * Constructor from both points.
79  */
80  TSegment3D(const TPoint3D& p1, const TPoint3D& p2) : point1(p1), point2(p2)
81  {
82  }
83  /**
84  * Fast default constructor. Initializes to garbage.
85  */
86  TSegment3D() = default;
87  /**
88  * Constructor from 2D object. Sets the z to zero.
89  */
90  explicit TSegment3D(const TSegment2D& s)
91  : point1(s.point1), point2(s.point2)
92  {
93  }
94 
95  bool operator<(const TSegment3D& s) const;
96 };
97 
98 inline bool operator==(const TSegment3D& s1, const TSegment3D& s2)
99 {
100  return (s1.point1 == s2.point1) && (s1.point2 == s2.point2);
101 }
102 
103 inline bool operator!=(const TSegment3D& s1, const TSegment3D& s2)
104 {
105  return (s1.point1 != s2.point1) || (s1.point2 != s2.point2);
106 }
107 
112 
113 } // namespace mrpt::math
114 
115 namespace mrpt::typemeta
116 {
117 // Specialization must occur in the same namespace
119 } // namespace mrpt::typemeta
bool contains(const TPoint3D &point) const
Check whether a point is inside the segment.
Definition: TSegment3D.cpp:112
TSegment3D(const TSegment2D &s)
Constructor from 2D object.
Definition: TSegment3D.h:90
mrpt::serialization::CArchive & operator>>(mrpt::serialization::CArchive &in, CMatrixD::Ptr &pObj)
TPoint3D point1
origin point
Definition: TSegment3D.h:23
This base provides a set of functions for maths stuff.
2D segment, consisting of two points.
Definition: TSegment2D.h:20
3D segment, consisting of two points.
Definition: TSegment3D.h:20
TPoint3D point2
final point
Definition: TSegment3D.h:24
double length() const
Segment length.
Definition: TSegment3D.cpp:25
const TPoint3D & operator[](size_t i) const
Access to points using operator[0-1].
Definition: TSegment3D.h:52
bool operator<(const TSegment3D &s) const
Definition: TSegment3D.cpp:120
#define MRPT_DECLARE_TTYPENAME_NO_NAMESPACE(_TYPE, __NS)
Declares a typename to be "type" (without the NS prefix)
Definition: TTypeName.h:128
void getCenter(TPoint3D &p) const
Segment&#39;s central point.
Definition: TSegment3D.h:71
double distance(const TPoint3D &point) const
Distance to point.
Definition: TSegment3D.cpp:26
constexpr bool operator==(const TPoint2D_< T > &p1, const TPoint2D_< T > &p2)
Exact comparison between 2D points.
Definition: TPoint2D.h:223
T x
X,Y,Z coordinates.
Definition: TPoint3D.h:29
constexpr bool operator!=(const TPoint2D_< T > &p1, const TPoint2D_< T > &p2)
Exact comparison between 2D points.
Definition: TPoint2D.h:230
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:54
mrpt::vision::TStereoCalibResults out
mrpt::serialization::CArchive & operator<<(mrpt::serialization::CArchive &s, const CVectorFloat &a)
Definition: math.cpp:626
TPoint3D & operator[](size_t i)
Access to points using operator[0-1].
Definition: TSegment3D.h:39
TSegment3D(const TPoint3D &p1, const TPoint3D &p2)
Constructor from both points.
Definition: TSegment3D.h:80
void generate2DObject(TSegment2D &s) const
Projection into 2D space, discarding the z.
Definition: TSegment3D.cpp:20
TSegment3D()=default
Fast default constructor.



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020