Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

GLine2D.h

Go to the documentation of this file.
00001 #ifndef GLINE2D_H
00002 #define GLINE2D_H
00003 
00004 #include <cmath>
00005 #include <utility>
00006 #include <vector>
00007 
00008 #include "Shared/fmat.h"
00009 #include "MathUtil.h"
00010 #include "XYWeight.h"
00011 
00012 namespace AprilTags {
00013 
00014 //! A 2D line
00015 class GLine2D {
00016 public:
00017 
00018   //! Create a new line.
00019   GLine2D();
00020 
00021   //! Create a new line.
00022   /*  @param slope the slope
00023    *  @param b the y intercept
00024    */
00025   GLine2D(float slope, float b);
00026 
00027   //! Create a new line.
00028   /*  @param dx A change in X corresponding to dy
00029    *  @param dy A change in Y corresponding to dx
00030    *  @param p A point that the line passes through
00031    */
00032   GLine2D(float dX, float dY, const std::pair<float,float>& pt);
00033 
00034   //! Create a new line through two points.
00035   /*  @param p1 the first point
00036    *  @param p2 the second point
00037    */
00038   GLine2D(const std::pair<float,float>& p1, const std::pair<float,float>& p2);
00039 
00040   //! Get the coordinate of a point (on this line), with zero corresponding to the point
00041   //! on the that is perpendicular toa line passing through the origin and the line.
00042   /*  This allows easy computation if one point is between two other points on the line:
00043    *  compute the line coordinate of all three points and test if a<=b<=c. This is 
00044    *  implemented by computing the dot product of the vector 'p' with the
00045    *  line's direct unit vector.
00046    */
00047   float getLineCoordinate(const std::pair<float,float>& p);
00048   
00049   //! The inverse of getLineCoordinate.
00050   std::pair<float,float> getPointOfCoordinate(float coord);
00051 
00052   //!Compute the point where two lines intersect, or (-1,0) if the lines are parallel.
00053   std::pair<float,float> intersectionWith(const GLine2D& line) const;
00054 
00055   static GLine2D lsqFitXYW(const std::vector<XYWeight>& xyweights);
00056 
00057   inline float getDx() const { return dx; }
00058   inline float getDy() const { return dy; }
00059   inline float getFirst() const { return p.first; }
00060   inline float getSecond() const { return p.second; }
00061 
00062 protected:
00063   void normalizeSlope();
00064   void normalizeP();
00065 
00066 private:
00067   float dx, dy;
00068   std::pair<float,float> p;  //!< A point the line passes through; when normalized, it is the point closest to the origin (hence perpendicular to the line)
00069   bool didNormalizeSlope;
00070   bool didNormalizeP;
00071 };
00072 
00073 } // namespace
00074 
00075 #endif

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:41 2016 by Doxygen 1.6.3