MRPT  2.0.4
TLine3D.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 <array>
13 
14 namespace mrpt::math
15 {
16 /** 3D line, represented by a base point and a director vector.
17  * \sa TLine2D,TSegment3D,TPlane,TPolygon3D,TPoint3D
18  */
19 struct TLine3D
20 {
21  public:
22  /** Fast default constructor. Initializes to all zeros. */
23  TLine3D() = default;
24 
25  /** Constructor from two points, through which the line will pass.
26  * \throw std::logic_error if both points are the same.
27  */
28  TLine3D(const TPoint3D& p1, const TPoint3D& p2);
29  /** Constructor from 3D segment */
30  explicit TLine3D(const TSegment3D& s);
31 
32  /** Constructor from 2D object. Zeroes the z. */
33  explicit TLine3D(const TLine2D& l);
34 
35  /** Static constructor from a point and a director vector.
36  * \note [New in MRPT 2.0.4]
37  */
39  const TPoint3D& basePoint, const TVector3D& directorVector);
40 
41  /** Static constructor from two points.
42  * \note [New in MRPT 2.0.4]
43  */
44  static TLine3D FromTwoPoints(const TPoint3D& p1, const TPoint3D& p2);
45 
46  /** Base point */
48  /** Director vector */
49  TVector3D director{.0, .0, .0};
50  /** Check whether a point is inside the line */
51  bool contains(const TPoint3D& point) const;
52  /**
53  * Distance between the line and a point.
54  */
55  double distance(const TPoint3D& point) const;
56  /**
57  * Unitarize director vector.
58  */
59  void unitarize();
60  /** Get director vector */
61  void getDirectorVector(double (&vector)[3]) const
62  {
63  for (size_t i = 0; i < 3; i++) vector[i] = director[i];
64  }
65  /** Get director vector (may be NOT unitary if not set so by the user) \sa
66  * getUnitaryDirectorVector(), unitarize() */
67  inline const TVector3D& getDirectorVector() const { return director; }
68 
69  /**
70  * Unitarize and then get director vector.
71  */
72  void getUnitaryDirectorVector(double (&vector)[3])
73  {
74  unitarize();
75  getDirectorVector(vector);
76  }
77  /**
78  * Project into 2D space, discarding the Z coordinate.
79  * \throw std::logic_error if the line's director vector is orthogonal to
80  * the XY plane.
81  */
82  void generate2DObject(TLine2D& l) const;
83 };
84 
89 
90 } // namespace mrpt::math
91 
92 namespace mrpt::typemeta
93 {
94 // Specialization must occur in the same namespace
96 } // namespace mrpt::typemeta
static TLine3D FromTwoPoints(const TPoint3D &p1, const TPoint3D &p2)
Static constructor from two points.
Definition: TLine3D.cpp:34
const TVector3D & getDirectorVector() const
Get director vector (may be NOT unitary if not set so by the user)
Definition: TLine3D.h:67
TPoint3D pBase
Base point.
Definition: TLine3D.h:47
void generate2DObject(TLine2D &l) const
Project into 2D space, discarding the Z coordinate.
Definition: TLine3D.cpp:23
mrpt::serialization::CArchive & operator>>(mrpt::serialization::CArchive &in, CMatrixD::Ptr &pObj)
void getUnitaryDirectorVector(double(&vector)[3])
Unitarize and then get director vector.
Definition: TLine3D.h:72
This base provides a set of functions for maths stuff.
3D segment, consisting of two points.
Definition: TSegment3D.h:20
void getDirectorVector(double(&vector)[3]) const
Get director vector.
Definition: TLine3D.h:61
TVector3D director
Director vector.
Definition: TLine3D.h:49
#define MRPT_DECLARE_TTYPENAME_NO_NAMESPACE(_TYPE, __NS)
Declares a typename to be "type" (without the NS prefix)
Definition: TTypeName.h:128
bool contains(const TPoint3D &point) const
Check whether a point is inside the line.
Definition: TLine3D.cpp:39
static TLine3D FromPointAndDirector(const TPoint3D &basePoint, const TVector3D &directorVector)
Static constructor from a point and a director vector.
Definition: TLine3D.cpp:25
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 unitarize()
Unitarize director vector.
Definition: TLine3D.cpp:70
TLine3D()=default
Fast default constructor.
double distance(const TPoint3D &point) const
Distance between the line and a point.
Definition: TLine3D.cpp:54
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