MRPT  2.0.1
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  /** Base point */
24  /** Director vector */
25  std::array<double, 3> director{{.0, .0, .0}};
26  /** Check whether a point is inside the line */
27  bool contains(const TPoint3D& point) const;
28  /**
29  * Distance between the line and a point.
30  */
31  double distance(const TPoint3D& point) const;
32  /**
33  * Unitarize director vector.
34  */
35  void unitarize();
36  /** Get director vector */
37  void getDirectorVector(double (&vector)[3]) const
38  {
39  for (size_t i = 0; i < 3; i++) vector[i] = director[i];
40  }
41  /** Get director vector */
43  {
44  TVector3D v;
45  for (int i = 0; i < 3; i++) v[i] = director[i];
46  return v;
47  }
48  /**
49  * Unitarize and then get director vector.
50  */
51  void getUnitaryDirectorVector(double (&vector)[3])
52  {
53  unitarize();
54  getDirectorVector(vector);
55  }
56  /**
57  * Project into 2D space, discarding the Z coordinate.
58  * \throw std::logic_error if the line's director vector is orthogonal to
59  * the XY plane.
60  */
61  void generate2DObject(TLine2D& l) const;
62  /**
63  * Constructor from two points, through which the line will pass.
64  * \throw std::logic_error if both points are the same.
65  */
66  TLine3D(const TPoint3D& p1, const TPoint3D& p2);
67  /**
68  * Constructor from 3D segment.
69  */
70  explicit TLine3D(const TSegment3D& s);
71  /**
72  * Fast default constructor. Initializes to garbage.
73  */
74  TLine3D() = default;
75  /** Constructor from 2D object. Zeroes the z. */
76  explicit TLine3D(const TLine2D& l);
77 };
78 
83 
84 } // namespace mrpt::math
85 
86 namespace mrpt::typemeta
87 {
88 // Specialization must occur in the same namespace
90 } // namespace mrpt::typemeta
TPoint3D pBase
Base point.
Definition: TLine3D.h:23
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:51
This base provides a set of functions for maths stuff.
3D segment, consisting of two points.
Definition: TSegment3D.h:20
std::array< double, 3 > director
Director vector.
Definition: TLine3D.h:25
void getDirectorVector(double(&vector)[3]) const
Get director vector.
Definition: TLine3D.h:37
#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: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:56
TVector3D getDirectorVector() const
Get director vector.
Definition: TLine3D.h:42
TLine3D()=default
Fast default constructor.
double distance(const TPoint3D &point) const
Distance between the line and a point.
Definition: TLine3D.cpp:40
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.1 Git: 0fef1a6d7 Fri Apr 3 23:00:21 2020 +0200 at vie abr 3 23:20:28 CEST 2020