MRPT  1.9.9
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-2019, 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 /**
18  * 3D segment, consisting of two points.
19  * \sa TSegment2D,TLine3D,TPlane,TPolygon3D,TPoint3D
20  */
21 struct TSegment3D
22 {
23  public:
24  /**
25  * Origin point.
26  */
28  /**
29  * Destiny point.
30  */
32  /**
33  * Segment length.
34  */
35  double length() const;
36  /**
37  * Distance to point.
38  */
39  double distance(const TPoint3D& point) const;
40  /**
41  * Distance to another segment.
42  */
43  double distance(const TSegment3D& segment) const;
44  /**
45  * Check whether a point is inside the segment.
46  */
47  bool contains(const TPoint3D& point) const;
48  /** Access to points using operator[0-1] */
49  TPoint3D& operator[](size_t i)
50  {
51  switch (i)
52  {
53  case 0:
54  return point1;
55  case 1:
56  return point2;
57  default:
58  throw std::out_of_range("index out of range");
59  }
60  }
61  /** Access to points using operator[0-1] */
62  const TPoint3D& operator[](size_t i) const
63  {
64  switch (i)
65  {
66  case 0:
67  return point1;
68  case 1:
69  return point2;
70  default:
71  throw std::out_of_range("index out of range");
72  }
73  }
74  /**
75  * Projection into 2D space, discarding the z.
76  */
77  void generate2DObject(TSegment2D& s) const;
78  /**
79  * Segment's central point.
80  */
81  void getCenter(TPoint3D& p) const
82  {
83  p.x = (point1.x + point2.x) / 2;
84  p.y = (point1.y + point2.y) / 2;
85  p.z = (point1.z + point2.z) / 2;
86  }
87  /**
88  * Constructor from both points.
89  */
90  TSegment3D(const TPoint3D& p1, const TPoint3D& p2) : point1(p1), point2(p2)
91  {
92  }
93  /**
94  * Fast default constructor. Initializes to garbage.
95  */
96  TSegment3D() = default;
97  /**
98  * Constructor from 2D object. Sets the z to zero.
99  */
100  explicit TSegment3D(const TSegment2D& s)
102  {
103  }
104 
105  bool operator<(const TSegment3D& s) const;
106 };
107 
108 inline bool operator==(const TSegment3D& s1, const TSegment3D& s2)
109 {
110  return (s1.point1 == s2.point1) && (s1.point2 == s2.point2);
111 }
112 
113 inline bool operator!=(const TSegment3D& s1, const TSegment3D& s2)
114 {
115  return (s1.point1 != s2.point1) || (s1.point2 != s2.point2);
116 }
117 
122 
123 } // namespace mrpt::math
124 
125 namespace mrpt::typemeta
126 {
127 // Specialization must occur in the same namespace
129 } // namespace mrpt::typemeta
double x
X,Y,Z coordinates.
Definition: TPoint3D.h:83
GLdouble s
Definition: glext.h:3682
TSegment3D(const TSegment2D &s)
Constructor from 2D object.
Definition: TSegment3D.h:100
bool operator<(const TSegment3D &s) const
mrpt::serialization::CArchive & operator>>(mrpt::serialization::CArchive &in, CMatrixD::Ptr &pObj)
TPoint3D point1
Origin point.
Definition: TSegment3D.h:27
This base provides a set of functions for maths stuff.
2D segment, consisting of two points.
Definition: TSegment2D.h:20
double distance(const TPoint3D &point) const
Distance to point.
3D segment, consisting of two points.
Definition: TSegment3D.h:21
TPoint3D point2
Destiny point.
Definition: TSegment3D.h:31
const TPoint3D & operator[](size_t i) const
Access to points using operator[0-1].
Definition: TSegment3D.h:62
#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:81
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:627
TPoint3D & operator[](size_t i)
Access to points using operator[0-1].
Definition: TSegment3D.h:49
GLuint in
Definition: glext.h:7391
bool contains(const TPoint3D &point) const
Check whether a point is inside the segment.
void generate2DObject(TSegment2D &s) const
Projection into 2D space, discarding the z.
TSegment3D(const TPoint3D &p1, const TPoint3D &p2)
Constructor from both points.
Definition: TSegment3D.h:90
Lightweight 3D point.
Definition: TPoint3D.h:90
constexpr bool operator==(const TPoint2D &p1, const TPoint2D &p2)
Exact comparison between 2D points.
Definition: TPoint2D.h:173
GLfloat GLfloat p
Definition: glext.h:6398
constexpr bool operator!=(const TPoint2D &p1, const TPoint2D &p2)
Exact comparison between 2D points.
Definition: TPoint2D.h:178
double length() const
Segment length.
TSegment3D()=default
Fast default constructor.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 836b840ab Mon Nov 18 00:58:29 2019 +0100 at lun nov 18 01:00:14 CET 2019