Line2D.hpp
Go to the documentation of this file.
00001 //
00002 // Line2D.hpp
00003 //
00004 
00005 #ifndef LINE2D_HPP
00006 #define LINE2D_HPP
00007 
00008 #include <iosfwd>
00009 #include "Point2D.hpp"
00010 #include "../BasicDatatypes.hpp"
00011 
00012 namespace datatypes
00013 {
00014         
00015 class Polygon2D;
00016 
00018 
00024 class Line2D : public BasicData
00025 {
00026 public:
00028         typedef Point2D value_type;
00030         typedef Point2D first_type;
00032         typedef Point2D second_type;
00033 
00035         enum IntersectingType
00036         {
00037                 NotIntersecting 
00038                 , LineIntersecting 
00039                 , OutsideIntersecting 
00040         };
00041 
00042 
00044         Line2D()
00045                 : first()
00046                 , second()
00047         {       m_datatype = Datatype_Line2D; }
00048 
00050         Line2D(const Point2D&a, const Point2D& b)
00051                 : first(a)
00052                 , second(b)
00053         { m_datatype = Datatype_Line2D; }
00054 
00056         Line2D(float x1, float y1, float x2, float y2)
00057                 : first(x1, y1)
00058                 , second(x2, y2)
00059         { m_datatype = Datatype_Line2D; }
00060 
00062         Line2D(const std::pair<Point2D, Point2D>& p)
00063                 : first(p.first)
00064                 , second(p.second)
00065         { m_datatype = Datatype_Line2D; }
00066 
00067         // Estimate the memory usage of this object
00068         inline virtual const UINT32 getUsedMemory() const {return (sizeof(*this));};
00069         
00070         
00071         std::string toString(); // Inhalt als lesbarer String
00072         
00074         static Line2D fromLinearRegression(const Polygon2D &points);
00075 
00077         //\{
00078 
00080         bool isZero() const { return first.isZero() && second.isZero(); }
00081 
00083         const Point2D& getP1() const { return first; }
00084 
00086         const Point2D& getP2() const { return second; }
00087 
00089         Point2D getCenterPoint() const;
00090 
00093         double getLength() const { return getDiff().dist(); }
00094 
00097         double length() const { return getLength(); }
00098 
00101         double getInclination() const;
00102 
00105         double inclination() const { return getInclination(); }
00106 
00108         // The returned value is getP2() - getP1().
00109         Point2D getDiff() const { return second - first; }
00110 
00112 
00116         Line2D getUnitVector() const;
00117 
00119         Polygon2D toPolygon2D() const;
00120 
00122         Polygon2D toPolygon2D(unsigned samplePoints) const;
00123 
00124         //\}
00125 
00126 
00128         //\{
00129 
00131         void setP1(const Point2D& p1) { first = p1; }
00132 
00134         void setP2(const Point2D& p2) { second = p2; }
00135 
00136         //\}
00137 
00138 
00140         //\{
00141 
00142 
00153         double distanceToPoint(const Point2D& point) const;
00154 
00165         double distanceFromLineSegment(const Point2D& point) const;
00166 
00169         Point2D projectOntoLine(const Point2D& point) const;
00170 
00177         bool containsPoint(const Point2D& point) const;
00178 
00180 
00186         IntersectingType isIntersecting(const Line2D& other,
00187                                                                         Point2D* intersectingPoint = NULL) const;
00188 
00189         //\}
00190 
00191 private:
00193         Point2D first;
00195         Point2D second;
00196 
00197 };
00198 
00199 // Text output for debugging
00200 std::ostream& operator<<(std::ostream& os, const Line2D& l);
00201 
00202 }       // namespace datatypes
00203 
00204 #endif


libsick_ldmrs
Author(s): SICK AG , Martin Günther , Jochen Sprickerhof
autogenerated on Wed Jun 14 2017 04:04:50