MRPT  1.9.9
TLine2D.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 |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10
11 #include <mrpt/math/TPoseOrPoint.h>
12 #include <array>
13
14 namespace mrpt::math
15 {
16 /** 2D line without bounds, represented by its equation \f$Ax+By+C=0\f$.
17  * \sa TLine3D,TSegment2D,TPolygon2D,TPoint2D
18  */
19 struct TLine2D
20 {
21  public:
22  /** Line coefficients, stored as an array: \f$\left[A,B,C\right]\f$ */
23  std::array<double, 3> coefs{{0, 0, 0}};
24  /**
25  * Evaluate point in the line's equation.
26  */
27  double evaluatePoint(const TPoint2D& point) const;
28  /**
29  * Check whether a point is inside the line.
30  */
31  bool contains(const TPoint2D& point) const;
32  /**
33  * Distance from a given point.
34  */
35  double distance(const TPoint2D& point) const;
36  /**
37  * Distance with sign from a given point (sign indicates side).
38  */
39  double signedDistance(const TPoint2D& point) const;
40  /**
41  * Get line's normal vector.
42  */
43  void getNormalVector(double (&vector)) const;
44  /**
45  * Unitarize line's normal vector.
46  */
47  void unitarize();
48  /**
49  * Get line's normal vector after unitarizing line.
50  */
51  void getUnitaryNormalVector(double (&vector))
52  {
53  unitarize();
54  getNormalVector(vector);
55  }
56  /**
57  * Get line's director vector.
58  */
59  void getDirectorVector(double (&vector)) const;
60  /**
61  * Unitarize line and then get director vector.
62  */
63  void getUnitaryDirectorVector(double (&vector))
64  {
65  unitarize();
66  getDirectorVector(vector);
67  }
68  /**
69  * Project into 3D space, setting the z to 0.
70  */
71  void generate3DObject(TLine3D& l) const;
72  /**
73  * Constructor from two points, through which the line will pass.
74  * \throw logic_error if both points are the same
75  */
76  TLine2D(const TPoint2D& p1, const TPoint2D& p2);
77  /**
78  * Constructor from a segment.
79  */
80  explicit TLine2D(const TSegment2D& s);
81  /**
82  * Fast default constructor. Initializes to garbage.
83  */
84  TLine2D() = default;
85  /**
86  * Constructor from line's coefficients.
87  */
88  constexpr TLine2D(double A, double B, double C) : coefs{A, B, C} {}
89  /**
90  * Construction from 3D object, discarding the Z.
91  * \throw std::logic_error if the line is normal to the XY plane.
92  */
93  explicit TLine2D(const TLine3D& l);
94  void getAsPose2D(TPose2D& outPose) const;
96  const TPoint2D& origin, TPose2D& outPose) const;
97 };
98
103
104 } // namespace mrpt::math
105
106 namespace mrpt::typemeta
107 {
108 // Specialization must occur in the same namespace
110 } // namespace mrpt::typemeta
void getUnitaryNormalVector(double(&vector))
Get line&#39;s normal vector after unitarizing line.
Definition: TLine2D.h:51
TPoint2D_< double > TPoint2D
Lightweight 2D point.
Definition: TPoint2D.h:204
void getDirectorVector(double(&vector)) const
Get line&#39;s director vector.
Definition: TLine2D.cpp:53
void unitarize()
Unitarize line&#39;s normal vector.
Definition: TLine2D.cpp:48
constexpr TLine2D(double A, double B, double C)
Constructor from line&#39;s coefficients.
Definition: TLine2D.h:88
void getUnitaryDirectorVector(double(&vector))
Unitarize line and then get director vector.
Definition: TLine2D.h:63
mrpt::serialization::CArchive & operator>>(mrpt::serialization::CArchive &in, CMatrixD::Ptr &pObj)
This base provides a set of functions for maths stuff.
2D segment, consisting of two points.
Definition: TSegment2D.h:20
double evaluatePoint(const TPoint2D &point) const
Evaluate point in the line&#39;s equation.
Definition: TLine2D.cpp:25
void generate3DObject(TLine3D &l) const
Project into 3D space, setting the z to 0.
Definition: TLine2D.cpp:58
void getAsPose2D(TPose2D &outPose) const
Definition: TLine2D.cpp:59
double distance(const TPoint2D &point) const
Distance from a given point.
Definition: TLine2D.cpp:33
#define MRPT_DECLARE_TTYPENAME_NO_NAMESPACE(_TYPE, __NS)
Declares a typename to be "type" (without the NS prefix)
Definition: TTypeName.h:128
void getAsPose2DForcingOrigin(const TPoint2D &origin, TPose2D &outPose) const
Definition: TLine2D.cpp:76
Base template for TPoint2D and TPoint2Df.
Definition: TPoint2D.h:31
std::array< double, 3 > coefs
Line coefficients, stored as an array: .
Definition: TLine2D.h:23
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
bool contains(const TPoint2D &point) const
Check whether a point is inside the line.
Definition: TLine2D.cpp:29
TLine2D()=default
Fast default constructor.
void getNormalVector(double(&vector)) const
Get line&#39;s normal vector.
Definition: TLine2D.cpp:43
double signedDistance(const TPoint2D &point) const
 Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 24b95e159 Thu Jan 23 01:15:46 2020 +0100 at jue ene 23 01:30:10 CET 2020 