MRPT  2.0.4
TSegment2D.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/TPoint2D.h>
12 #include <mrpt/math/TPoseOrPoint.h>
13 
14 namespace mrpt::math
15 {
16 /**
17  * 2D segment, consisting of two points.
18  * \sa TSegment3D,TLine2D,TPolygon2D,TPoint2D
19  */
20 struct TSegment2D
21 {
22  public:
23  /**
24  * Origin point.
25  */
27  /**
28  * Destiny point.
29  */
31  /**
32  * Segment length.
33  */
34  double length() const;
35  /**
36  * Distance to point.
37  */
38  double distance(const TPoint2D& point) const;
39  /**
40  * Distance with sign to point (sign indicates which side the point is).
41  */
42  double signedDistance(const TPoint2D& point) const;
43  /**
44  * Check whether a point is inside a segment.
45  */
46  bool contains(const TPoint2D& point) const;
47  /** Access to points using operator[0-1] */
48  TPoint2D& operator[](size_t i)
49  {
50  switch (i)
51  {
52  case 0:
53  return point1;
54  case 1:
55  return point2;
56  default:
57  throw std::out_of_range("index out of range");
58  }
59  }
60  /** Access to points using operator[0-1] */
61  constexpr const TPoint2D& operator[](size_t i) const
62  {
63  switch (i)
64  {
65  case 0:
66  return point1;
67  case 1:
68  return point2;
69  default:
70  throw std::out_of_range("index out of range");
71  }
72  }
73  /**
74  * Project into 3D space, setting the z to 0.
75  */
76  void generate3DObject(TSegment3D& s) const;
77  /**
78  * Segment's central point.
79  */
80  void getCenter(TPoint2D& p) const
81  {
82  p.x = (point1.x + point2.x) / 2;
83  p.y = (point1.y + point2.y) / 2;
84  }
85  /**
86  * Constructor from both points.
87  */
88  TSegment2D(const TPoint2D& p1, const TPoint2D& p2) : point1(p1), point2(p2)
89  {
90  }
91  /**
92  * Fast default constructor. Initializes to garbage.
93  */
94  TSegment2D() = default;
95  /**
96  * Explicit constructor from 3D object, discarding the z.
97  */
98  explicit TSegment2D(const TSegment3D& s);
99 
100  bool operator<(const TSegment2D& s) const;
101 };
102 
103 inline bool operator==(const TSegment2D& s1, const TSegment2D& s2)
104 {
105  return (s1.point1 == s2.point1) && (s1.point2 == s2.point2);
106 }
107 
108 inline bool operator!=(const TSegment2D& s1, const TSegment2D& s2)
109 {
110  return (s1.point1 != s2.point1) || (s1.point2 != s2.point2);
111 }
112 
117 
118 } // namespace mrpt::math
119 
120 namespace mrpt::typemeta
121 {
122 // Specialization must occur in the same namespace
124 
125 } // namespace mrpt::typemeta
void getCenter(TPoint2D &p) const
Segment&#39;s central point.
Definition: TSegment2D.h:80
TSegment2D(const TPoint2D &p1, const TPoint2D &p2)
Constructor from both points.
Definition: TSegment2D.h:88
double distance(const TPoint2D &point) const
Distance to point.
Definition: TSegment2D.cpp:19
T x
X,Y coordinates.
Definition: TPoint2D.h:25
constexpr const TPoint2D & operator[](size_t i) const
Access to points using operator[0-1].
Definition: TSegment2D.h:61
double length() const
Segment length.
Definition: TSegment2D.cpp:18
mrpt::serialization::CArchive & operator>>(mrpt::serialization::CArchive &in, CMatrixD::Ptr &pObj)
double signedDistance(const TPoint2D &point) const
Distance with sign to point (sign indicates which side the point is).
Definition: TSegment2D.cpp: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
TSegment2D()=default
Fast default constructor.
#define MRPT_DECLARE_TTYPENAME_NO_NAMESPACE(_TYPE, __NS)
Declares a typename to be "type" (without the NS prefix)
Definition: TTypeName.h:128
bool operator<(const TSegment2D &s) const
Definition: TSegment2D.cpp:63
TPoint2D point2
Destiny point.
Definition: TSegment2D.h:30
TPoint2D & operator[](size_t i)
Access to points using operator[0-1].
Definition: TSegment2D.h:48
bool contains(const TPoint2D &point) const
Check whether a point is inside a segment.
Definition: TSegment2D.cpp:45
constexpr bool operator==(const TPoint2D_< T > &p1, const TPoint2D_< T > &p2)
Exact comparison between 2D points.
Definition: TPoint2D.h:223
TPoint2D point1
Origin point.
Definition: TSegment2D.h:26
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
void generate3DObject(TSegment3D &s) const
Project into 3D space, setting the z to 0.
Definition: TSegment2D.cpp:51



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