Line2D.hpp
Go to the documentation of this file.
1 //
2 // Line2D.hpp
3 //
4 
5 #ifndef LINE2D_HPP
6 #define LINE2D_HPP
7 
8 #include <iosfwd>
9 #include "Point2D.hpp"
10 #include "../BasicDatatypes.hpp"
11 
12 namespace datatypes
13 {
14 
15 class Polygon2D;
16 
18 
24 class Line2D : public BasicData
25 {
26 public:
33 
36  {
40  };
41 
42 
45  : first()
46  , second()
48 
50  Line2D(const Point2D&a, const Point2D& b)
51  : first(a)
52  , second(b)
54 
56  Line2D(float x1, float y1, float x2, float y2)
57  : first(x1, y1)
58  , second(x2, y2)
60 
62  Line2D(const std::pair<Point2D, Point2D>& p)
63  : first(p.first)
64  , second(p.second)
66 
67  // Estimate the memory usage of this object
68  inline virtual const UINT32 getUsedMemory() const {return (sizeof(*this));};
69 
70 
71  std::string toString(); // Inhalt als lesbarer String
72 
74  static Line2D fromLinearRegression(const Polygon2D &points);
75 
77  //\{
78 
80  bool isZero() const { return first.isZero() && second.isZero(); }
81 
83  const Point2D& getP1() const { return first; }
84 
86  const Point2D& getP2() const { return second; }
87 
89  Point2D getCenterPoint() const;
90 
93  double getLength() const { return getDiff().dist(); }
94 
97  double length() const { return getLength(); }
98 
101  double getInclination() const;
102 
105  double inclination() const { return getInclination(); }
106 
108  // The returned value is getP2() - getP1().
109  Point2D getDiff() const { return second - first; }
110 
112 
116  Line2D getUnitVector() const;
117 
119  Polygon2D toPolygon2D() const;
120 
122  Polygon2D toPolygon2D(unsigned samplePoints) const;
123 
124  //\}
125 
126 
128  //\{
129 
131  void setP1(const Point2D& p1) { first = p1; }
132 
134  void setP2(const Point2D& p2) { second = p2; }
135 
136  //\}
137 
138 
140  //\{
141 
142 
153  double distanceToPoint(const Point2D& point) const;
154 
165  double distanceFromLineSegment(const Point2D& point) const;
166 
169  Point2D projectOntoLine(const Point2D& point) const;
170 
177  bool containsPoint(const Point2D& point) const;
178 
180 
187  Point2D* intersectingPoint = NULL) const;
188 
189  //\}
190 
191 private:
196 
197 };
198 
199 // Text output for debugging
200 std::ostream& operator<<(std::ostream& os, const Line2D& l);
201 
202 } // namespace datatypes
203 
204 #endif
IntersectingType
Describes how two lines can be intersecting.
Definition: Line2D.hpp:35
double getLength() const
Definition: Line2D.hpp:93
const Point2D & getP1() const
Returns the first point.
Definition: Line2D.hpp:83
Line2D()
Empty constructor.
Definition: Line2D.hpp:44
uint32_t UINT32
A polygon of 2D-points.
Definition: Polygon2D.hpp:43
double distanceToPoint(const Point2D &point) const
Returns the distance of the given point to its orthogonal projection onto this line.
Definition: Line2D.cpp:81
void setP1(const Point2D &p1)
Sets the first point.
Definition: Line2D.hpp:131
Point2D second
The second point of this line.
Definition: Line2D.hpp:195
value_type dist() const
Definition: Point2D.hpp:353
bool isZero() const
Definition: Point2D.hpp:296
Line2D(const Point2D &a, const Point2D &b)
Constructor with two points.
Definition: Line2D.hpp:50
bool containsPoint(const Point2D &point) const
Returns true if this line "contains" the given point.
Definition: Line2D.cpp:75
Point2D second_type
Typedef for STL std::pair compatibility.
Definition: Line2D.hpp:32
Point2D first_type
Typedef for STL std::pair compatibility.
Definition: Line2D.hpp:30
Point2D getDiff() const
Returns the difference between line end and line start as a Point2D.
Definition: Line2D.hpp:109
The lines are not intersecting, i.e. they are parallel or zero.
Definition: Line2D.hpp:37
std::string toString()
Definition: Line2D.cpp:66
Polygon2D toPolygon2D() const
Conversion to Polygon2D.
Definition: Line2D.cpp:17
Point2D projectOntoLine(const Point2D &point) const
Definition: Line2D.cpp:91
A line in the two-dimensional plane, composed out of two points.
Definition: Line2D.hpp:24
Point2D value_type
Typedef for STL compatibility.
Definition: Line2D.hpp:28
Point2D first
The first point of this line.
Definition: Line2D.hpp:193
static Line2D fromLinearRegression(const Polygon2D &points)
Returns a Line2D from several points using linear regression.
Definition: Line2D.cpp:309
double distanceFromLineSegment(const Point2D &point) const
Returns the distance of a point to this line segment.
Definition: Line2D.cpp:110
bool isZero() const
Returns true if both points are zero.
Definition: Line2D.hpp:80
The lines are intersecting, but outside of their line segments.
Definition: Line2D.hpp:39
IntersectingType isIntersecting(const Line2D &other, Point2D *intersectingPoint=NULL) const
Calculates the intersection point between two lines.
Definition: Line2D.cpp:258
Line2D(const std::pair< Point2D, Point2D > &p)
Constructor from a std::pair.
Definition: Line2D.hpp:62
Line2D(float x1, float y1, float x2, float y2)
Constructor with x/y coordinates of the two points given explicitly.
Definition: Line2D.hpp:56
The lines are intersecting within their line segments.
Definition: Line2D.hpp:38
Point2D getCenterPoint() const
Returns the point in the middle between first and second point.
Definition: Line2D.cpp:339
void setP2(const Point2D &p2)
Sets the second point.
Definition: Line2D.hpp:134
double length() const
Definition: Line2D.hpp:97
virtual const UINT32 getUsedMemory() const
Definition: Line2D.hpp:68
Line2D getUnitVector() const
Returns a unit vector for this line.
Definition: Line2D.cpp:56
std::ostream & operator<<(std::ostream &os, const EvalCaseResult &result)
const Point2D & getP2() const
Returns the second point.
Definition: Line2D.hpp:86
double inclination() const
Definition: Line2D.hpp:105
double getInclination() const
Definition: Line2D.cpp:42


libsick_ldmrs
Author(s): SICK AG , Martin Günther , Jochen Sprickerhof
autogenerated on Mon Oct 26 2020 03:27:30