MRPT  2.0.0
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-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/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  TVector3D getNormalVector() const;
55  /**
56  * Unitarize normal vector.
57  */
58  void unitarize();
59  void getAsPose3D(mrpt::math::TPose3D& outPose) const;
60  void getAsPose3DForcingOrigin(const TPoint3D& center, TPose3D& pose) const;
61  /** Get normal vector */
63  /** Defines a plane which contains these three points.
64  * \throw std::logic_error if the points are linearly dependants.
65  */
66  TPlane(const TPoint3D& p1, const TPoint3D& p2, const TPoint3D& p3);
67  /** Defines a plane given a point and a normal vector (must not be unit).
68  * \throw std::logic_error if the normal vector is null
69  */
70  TPlane(const TPoint3D& p1, const TVector3D& normal);
71  /** Defines a plane which contains this point and this line.
72  * \throw std::logic_error if the point is inside the line.
73  */
74  TPlane(const TPoint3D& p1, const TLine3D& r2);
75  /** Defines a plane which contains the two lines.
76  * \throw std::logic_error if the lines do not cross.
77  */
78  TPlane(const TLine3D& r1, const TLine3D& r2);
79  /** Fast default constructor. Initializes to garbage. */
80  TPlane() = default;
81  /** Constructor from plane coefficients */
82  constexpr TPlane(double A, double B, double C, double D) : coefs{A, B, C, D}
83  {
84  }
85  /**
86  * Constructor from an array of coefficients.
87  */
88  TPlane(const double (&vec)[4])
89  {
90  for (size_t i = 0; i < 4; i++) coefs[i] = vec[i];
91  }
92 };
93 
94 using TPlane3D = TPlane;
95 
100 
101 } // namespace mrpt::math
102 
103 namespace mrpt::typemeta
104 {
105 // Specialization must occur in the same namespace
107 
108 } // namespace mrpt::typemeta
bool contains(const TSegment3D &segment) const
Check whether a segment is fully contained into the plane.
Definition: TPlane.h:36
TVector3D getUnitaryNormalVector() const
Get normal vector.
Definition: TPlane.cpp:56
mrpt::serialization::CArchive & operator>>(mrpt::serialization::CArchive &in, CMatrixD::Ptr &pObj)
TPoint3D point1
origin point
Definition: TSegment3D.h:23
void getAsPose3D(mrpt::math::TPose3D &outPose) const
Definition: TPlane.cpp:73
This base provides a set of functions for maths stuff.
TPlane(const double(&vec)[4])
Constructor from an array of coefficients.
Definition: TPlane.h:88
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:20
TPoint3D point2
final point
Definition: TSegment3D.h:24
void getAsPose3DForcingOrigin(const TPoint3D &center, TPose3D &pose) const
Definition: TPlane.cpp:85
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:82
void unitarize()
Unitarize normal vector.
Definition: TPlane.cpp:66
#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:626
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
Get plane&#39;s normal vector.
Definition: TPlane.cpp:49
3D line, represented by a base point and a director vector.
Definition: TLine3D.h:19



Page generated by Doxygen 1.8.14 for MRPT 2.0.0 Git: b38439d21 Tue Mar 31 19:58:06 2020 +0200 at miƩ abr 1 00:50:30 CEST 2020