A line in the two-dimensional plane, composed out of two points. More...
#include <Line2D.hpp>
Public Types | |
typedef Point2D | first_type |
Typedef for STL std::pair compatibility. More... | |
enum | IntersectingType { NotIntersecting, LineIntersecting, OutsideIntersecting } |
Describes how two lines can be intersecting. More... | |
typedef Point2D | second_type |
Typedef for STL std::pair compatibility. More... | |
typedef Point2D | value_type |
Typedef for STL compatibility. More... | |
Public Member Functions | |
virtual const UINT32 | getUsedMemory () const |
Line2D () | |
Empty constructor. More... | |
Line2D (const Point2D &a, const Point2D &b) | |
Constructor with two points. More... | |
Line2D (float x1, float y1, float x2, float y2) | |
Constructor with x/y coordinates of the two points given explicitly. More... | |
Line2D (const std::pair< Point2D, Point2D > &p) | |
Constructor from a std::pair. More... | |
std::string | toString () |
Accessor methods for information about this line | |
bool | isZero () const |
Returns true if both points are zero. More... | |
const Point2D & | getP1 () const |
Returns the first point. More... | |
const Point2D & | getP2 () const |
Returns the second point. More... | |
Point2D | getCenterPoint () const |
Returns the point in the middle between first and second point. More... | |
double | getLength () const |
double | length () const |
double | getInclination () const |
double | inclination () const |
Point2D | getDiff () const |
Returns the difference between line end and line start as a Point2D. More... | |
Line2D | getUnitVector () const |
Returns a unit vector for this line. More... | |
Polygon2D | toPolygon2D () const |
Conversion to Polygon2D. More... | |
Polygon2D | toPolygon2D (unsigned samplePoints) const |
Conversion to Polygon2D with more than 2 sampling points. More... | |
Setter methods for changing this line | |
void | setP1 (const Point2D &p1) |
Sets the first point. More... | |
void | setP2 (const Point2D &p2) |
Sets the second point. More... | |
Geometrical relations to other objects | |
double | distanceToPoint (const Point2D &point) const |
Returns the distance of the given point to its orthogonal projection onto this line. More... | |
double | distanceFromLineSegment (const Point2D &point) const |
Returns the distance of a point to this line segment. More... | |
Point2D | projectOntoLine (const Point2D &point) const |
bool | containsPoint (const Point2D &point) const |
Returns true if this line "contains" the given point. More... | |
IntersectingType | isIntersecting (const Line2D &other, Point2D *intersectingPoint=NULL) const |
Calculates the intersection point between two lines. More... | |
Public Member Functions inherited from datatypes::BasicData | |
BasicData () | |
UINT16 | getDatatype () |
UINT16 | getSourceId () |
virtual void | setSourceId (UINT16 id) |
virtual | ~BasicData () |
Static Public Member Functions | |
static Line2D | fromLinearRegression (const Polygon2D &points) |
Returns a Line2D from several points using linear regression. More... | |
Private Attributes | |
Point2D | first |
The first point of this line. More... | |
Point2D | second |
The second point of this line. More... | |
Additional Inherited Members | |
Protected Attributes inherited from datatypes::BasicData | |
UINT16 | m_datatype |
UINT16 | m_sourceId |
A line in the two-dimensional plane, composed out of two points.
This class is a line composed out of two points and offers some helper methods for simple geometrical calculations.
Definition at line 24 of file Line2D.hpp.
typedef Point2D datatypes::Line2D::first_type |
Typedef for STL std::pair compatibility.
Definition at line 30 of file Line2D.hpp.
Typedef for STL std::pair compatibility.
Definition at line 32 of file Line2D.hpp.
typedef Point2D datatypes::Line2D::value_type |
Typedef for STL compatibility.
Definition at line 28 of file Line2D.hpp.
Describes how two lines can be intersecting.
Definition at line 35 of file Line2D.hpp.
|
inline |
Empty constructor.
Definition at line 44 of file Line2D.hpp.
Constructor with two points.
Definition at line 50 of file Line2D.hpp.
|
inline |
Constructor with x/y coordinates of the two points given explicitly.
Definition at line 56 of file Line2D.hpp.
Constructor from a std::pair.
Definition at line 62 of file Line2D.hpp.
bool datatypes::Line2D::containsPoint | ( | const Point2D & | point | ) | const |
Returns true if this line "contains" the given point.
Computes the distance from the point to the line, and if it is zero, the point lies on the line and this method returns true.
Definition at line 75 of file Line2D.cpp.
double datatypes::Line2D::distanceFromLineSegment | ( | const Point2D & | point | ) | const |
Returns the distance of a point to this line segment.
If the point's projection onto the line is between the end points of this line, the distance to the projected point is returnd. If the projection is not on the line segment, the distance to the closest end point is returned. Alternatively, distanceToPoint() returns the distance to the point's projection in all cases.
Definition at line 110 of file Line2D.cpp.
double datatypes::Line2D::distanceToPoint | ( | const Point2D & | point | ) | const |
Returns the distance of the given point to its orthogonal projection onto this line.
The calculated distance is always the distance from the point to the point's projection onto the line, even if the point's projection is not between the end points of the line. Alternatively, distanceFromLineSegment() returns the distance to the line's end point in that case.
Definition at line 81 of file Line2D.cpp.
Returns a Line2D from several points using linear regression.
Definition at line 309 of file Line2D.cpp.
Point2D datatypes::Line2D::getCenterPoint | ( | ) | const |
Returns the point in the middle between first and second point.
Definition at line 339 of file Line2D.cpp.
|
inline |
Returns the difference between line end and line start as a Point2D.
Definition at line 109 of file Line2D.hpp.
double datatypes::Line2D::getInclination | ( | ) | const |
Calculates the rising angle of a line: the inclination angle. Returns a value in [-PI,PI] in radians.
Definition at line 42 of file Line2D.cpp.
|
inline |
Returns the length of this line, i.e. the distance of the two points.
Definition at line 93 of file Line2D.hpp.
|
inline |
Returns the first point.
Definition at line 83 of file Line2D.hpp.
|
inline |
Returns the second point.
Definition at line 86 of file Line2D.hpp.
Line2D datatypes::Line2D::getUnitVector | ( | ) | const |
Returns a unit vector for this line.
The returned unit vector has the same starting point as this line (which is getP1()) and it has a length of 1.0.
Definition at line 56 of file Line2D.cpp.
|
inlinevirtual |
Implements datatypes::BasicData.
Definition at line 68 of file Line2D.hpp.
|
inline |
Deprecated. Calculates the rising angle of a line: the inclination angle. Returns a value in [-PI,PI] in radians.
Definition at line 105 of file Line2D.hpp.
Line2D::IntersectingType datatypes::Line2D::isIntersecting | ( | const Line2D & | other, |
Point2D * | intersectingPoint = NULL |
||
) | const |
Calculates the intersection point between two lines.
The returned value describes whether the two lines intersect within their line segments, or outside of their line segments, or not at all. The actual intersection point is written to intersectingPoint if that pointer is non-NULL.
Definition at line 258 of file Line2D.cpp.
|
inline |
Returns true if both points are zero.
Definition at line 80 of file Line2D.hpp.
|
inline |
Deprecated. Returns the length of this line, i.e. the distance of the two points.
Definition at line 97 of file Line2D.hpp.
Calculates and returns the point that results when projecting the given point onto this line orthogonally.
Definition at line 91 of file Line2D.cpp.
|
inline |
Sets the first point.
Definition at line 131 of file Line2D.hpp.
|
inline |
Sets the second point.
Definition at line 134 of file Line2D.hpp.
Polygon2D datatypes::Line2D::toPolygon2D | ( | ) | const |
Conversion to Polygon2D.
Definition at line 17 of file Line2D.cpp.
Polygon2D datatypes::Line2D::toPolygon2D | ( | unsigned | samplePoints | ) | const |
Conversion to Polygon2D with more than 2 sampling points.
Definition at line 22 of file Line2D.cpp.
std::string datatypes::Line2D::toString | ( | ) |
Definition at line 66 of file Line2D.cpp.
|
private |
The first point of this line.
Definition at line 193 of file Line2D.hpp.
|
private |
The second point of this line.
Definition at line 195 of file Line2D.hpp.