MRPT  2.0.4
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-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/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  /** Constructor from two points, through which the line will pass.
23  * \throw logic_error if both points are the same
24  */
25  TLine2D(const TPoint2D& p1, const TPoint2D& p2);
26 
27  /** Constructor from a segment */
28  explicit TLine2D(const TSegment2D& s);
29 
30  /** Fast default constructor. Initializes to undefined values. */
31  TLine2D() = default;
32 
33  /** Constructor from line's coefficients */
34  constexpr TLine2D(double A, double B, double C) : coefs{A, B, C} {}
35 
36  /** Construction from 3D object, discarding the Z.
37  * \throw std::logic_error if the line is normal to the XY plane.
38  */
39  explicit TLine2D(const TLine3D& l);
40 
41  /** Static constructor from Ax+By+C=0 coefficients.
42  * \note [New in MRPT 2.0.4]
43  */
44  static TLine2D FromCoefficientsABC(double A, double B, double C);
45 
46  /** Static constructor from two points.
47  * \note [New in MRPT 2.0.4]
48  */
49  static TLine2D FromTwoPoints(const TPoint2D& p1, const TPoint2D& p2);
50 
51  /** Line coefficients, stored as an array: \f$\left[A,B,C\right]\f$ */
52  std::array<double, 3> coefs{{0, 0, 0}};
53  /**
54  * Evaluate point in the line's equation.
55  */
56  double evaluatePoint(const TPoint2D& point) const;
57  /**
58  * Check whether a point is inside the line.
59  */
60  bool contains(const TPoint2D& point) const;
61  /**
62  * Distance from a given point.
63  */
64  double distance(const TPoint2D& point) const;
65  /**
66  * Distance with sign from a given point (sign indicates side).
67  */
68  double signedDistance(const TPoint2D& point) const;
69  /**
70  * Get line's normal vector.
71  */
72  void getNormalVector(double (&vector)[2]) const;
73  /**
74  * Unitarize line's normal vector.
75  */
76  void unitarize();
77  /**
78  * Get line's normal vector after unitarizing line.
79  */
80  void getUnitaryNormalVector(double (&vector)[2])
81  {
82  unitarize();
83  getNormalVector(vector);
84  }
85  /**
86  * Get line's director vector.
87  */
88  void getDirectorVector(double (&vector)[2]) const;
89  /**
90  * Unitarize line and then get director vector.
91  */
92  void getUnitaryDirectorVector(double (&vector)[2])
93  {
94  unitarize();
95  getDirectorVector(vector);
96  }
97  /**
98  * Project into 3D space, setting the z to 0.
99  */
100  void generate3DObject(TLine3D& l) const;
101 
102  void getAsPose2D(TPose2D& outPose) const;
104  const TPoint2D& origin, TPose2D& outPose) const;
105 };
106 
111 
112 } // namespace mrpt::math
113 
114 namespace mrpt::typemeta
115 {
116 // Specialization must occur in the same namespace
118 } // namespace mrpt::typemeta
void getUnitaryNormalVector(double(&vector)[2])
Get line&#39;s normal vector after unitarizing line.
Definition: TLine2D.h:80
TPoint2D_< double > TPoint2D
Lightweight 2D point.
Definition: TPoint2D.h:213
void getDirectorVector(double(&vector)[2]) const
Get line&#39;s director vector.
Definition: TLine2D.cpp:63
void unitarize()
Unitarize line&#39;s normal vector.
Definition: TLine2D.cpp:58
constexpr TLine2D(double A, double B, double C)
Constructor from line&#39;s coefficients.
Definition: TLine2D.h:34
void getUnitaryDirectorVector(double(&vector)[2])
Unitarize line and then get director vector.
Definition: TLine2D.h:92
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:35
void generate3DObject(TLine3D &l) const
Project into 3D space, setting the z to 0.
Definition: TLine2D.cpp:68
void getAsPose2D(TPose2D &outPose) const
Definition: TLine2D.cpp:69
double distance(const TPoint2D &point) const
Distance from a given point.
Definition: TLine2D.cpp:43
static TLine2D FromCoefficientsABC(double A, double B, double C)
Static constructor from Ax+By+C=0 coefficients.
Definition: TLine2D.cpp:25
#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:86
std::array< double, 3 > coefs
Line coefficients, stored as an array: .
Definition: TLine2D.h:52
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
Lightweight 2D pose.
Definition: TPose2D.h:22
bool contains(const TPoint2D &point) const
Check whether a point is inside the line.
Definition: TLine2D.cpp:39
static TLine2D FromTwoPoints(const TPoint2D &p1, const TPoint2D &p2)
Static constructor from two points.
Definition: TLine2D.cpp:30
TLine2D()=default
Fast default constructor.
void getNormalVector(double(&vector)[2]) const
Get line&#39;s normal vector.
Definition: TLine2D.cpp:53
double signedDistance(const TPoint2D &point) const
Distance with sign from a given point (sign indicates side).
Definition: TLine2D.cpp:48
3D line, represented by a base point and a director vector.
Definition: TLine3D.h:19
2D line without bounds, represented by its equation .
Definition: TLine2D.h:19



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