MRPT  1.9.9
TPlane.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/TPoint3D.h>
12 #include <mrpt/math/TPoseOrPoint.h>
13 #include <mrpt/math/TSegment3D.h>
14 #include <array>
15
16 namespace mrpt::math
17 {
18 /**
19  * 3D Plane, represented by its equation \f$Ax+By+Cz+D=0\f$
20  * \sa TSegment3D,TLine3D,TPolygon3D,TPoint3D
21  */
22 struct TPlane
23 {
24  public:
25  /** Plane coefficients, stored as an array: \f$\left[A,B,C,D\right]\f$ */
26  std::array<double, 4> coefs{{.0, .0, .0, .0}};
27  /** Evaluate a point in the plane's equation */
28  double evaluatePoint(const TPoint3D& point) const;
29  /**
30  * Check whether a point is contained into the plane.
31  */
32  bool contains(const TPoint3D& point) const;
33  /**
34  * Check whether a segment is fully contained into the plane.
35  */
36  bool contains(const TSegment3D& segment) const
37  {
38  return contains(segment.point1) && contains(segment.point2);
39  }
40  /**
41  * Check whether a line is fully contained into the plane.
42  */
43  bool contains(const TLine3D& line) const;
44  /**
45  * Distance to 3D point.
46  */
47  double distance(const TPoint3D& point) const;
48  /**
49  * Distance to 3D line. Will be zero if the line is not parallel to the
50  * plane.
51  */
52  double distance(const TLine3D& line) const;
53  /** Get plane's normal vector */
54  void getNormalVector(double (&vec)) const;
56  TVector3D getNormalVector() const;
57  /**
58  * Unitarize normal vector.
59  */
60  void unitarize();
61  void getAsPose3D(mrpt::math::TPose3D& outPose) const;
62  void getAsPose3DForcingOrigin(const TPoint3D& center, TPose3D& pose) const;
63  /** Get normal vector */
64  void getUnitaryNormalVector(double (&vec)) const;
65  /** Defines a plane which contains these three points.
66  * \throw std::logic_error if the points are linearly dependants.
67  */
68  TPlane(const TPoint3D& p1, const TPoint3D& p2, const TPoint3D& p3);
69  /** Defines a plane given a point and a normal vector (must not be unit).
70  * \throw std::logic_error if the normal vector is null
71  */
72  TPlane(const TPoint3D& p1, const TVector3D& normal);
73  /** Defines a plane which contains this point and this line.
74  * \throw std::logic_error if the point is inside the line.
75  */
76  TPlane(const TPoint3D& p1, const TLine3D& r2);
77  /** Defines a plane which contains the two lines.
78  * \throw std::logic_error if the lines do not cross.
79  */
80  TPlane(const TLine3D& r1, const TLine3D& r2);
81  /** Fast default constructor. Initializes to garbage. */
82  TPlane() = default;
83  /** Constructor from plane coefficients */
84  constexpr TPlane(double A, double B, double C, double D) : coefs{A, B, C, D}
85  {
86  }
87  /**
88  * Constructor from an array of coefficients.
89  */
90  TPlane(const double (&vec))
91  {
92  for (size_t i = 0; i < 4; i++) coefs[i] = vec[i];
93  }
94 };
95
96 using TPlane3D = TPlane;
97
102
103 } // namespace mrpt::math
104
105 namespace mrpt::typemeta
106 {
107 // Specialization must occur in the same namespace
109
110 } // namespace mrpt::typemeta
bool contains(const TSegment3D &segment) const
Check whether a segment is fully contained into the plane.
Definition: TPlane.h:36
mrpt::serialization::CArchive & operator>>(mrpt::serialization::CArchive &in, CMatrixD::Ptr &pObj)
TPoint3D point1
Origin point.
Definition: TSegment3D.h:27
void getAsPose3D(mrpt::math::TPose3D &outPose) const
Definition: TPlane.cpp:75
This base provides a set of functions for maths stuff.
TPlane(const double(&vec))
Constructor from an array of coefficients.
Definition: TPlane.h:90
double evaluatePoint(const TPoint3D &point) const
Evaluate a point in the plane&#39;s equation.
Definition: TPlane.cpp:24
3D segment, consisting of two points.
Definition: TSegment3D.h:21
TPoint3D point2
Destiny point.
Definition: TSegment3D.h:31
void getUnitaryNormalVector(double(&vec)) const
Get normal vector.
Definition: TPlane.cpp:60
void getAsPose3DForcingOrigin(const TPoint3D &center, TPose3D &pose) const
Definition: TPlane.cpp:89
3D Plane, represented by its equation
Definition: TPlane.h:22
constexpr TPlane(double A, double B, double C, double D)
Constructor from plane coefficients.
Definition: TPlane.h:84
void unitarize()
Unitarize normal vector.
Definition: TPlane.cpp:68
#define MRPT_DECLARE_TTYPENAME_NO_NAMESPACE(_TYPE, __NS)
Declares a typename to be "type" (without the NS prefix)
Definition: TTypeName.h:128
double distance(const TPoint3D &point) const
Distance to 3D point.
Definition: TPlane.cpp:38
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
Lightweight 3D pose (three spatial coordinates, plus three angular coordinates).
Definition: TPose3D.h:24
bool contains(const TPoint3D &point) const
Check whether a point is contained into the plane.
Definition: TPlane.cpp:28
TPlane()=default
Fast default constructor.
std::array< double, 4 > coefs
Plane coefficients, stored as an array: .
Definition: TPlane.h:26
TVector3D getNormalVector() const
Definition: TPlane.cpp:53
3D line, represented by a base point and a director vector.
Definition: TLine3D.h:19

 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 