Line2D.h
Go to the documentation of this file.
00001 /*******************************************************************************
00002  *  Line2D.h
00003  *
00004  *  (C) 2008 AG Aktives Sehen <agas@uni-koblenz.de>
00005  *           Universitaet Koblenz-Landau
00006  *
00007  *  Information on Code Review state:
00008  *  Author: SM; DevelTest: Date; Reviewer: Initials; Review: Date; State: NOK
00009  *
00010  *  Additional information:
00011  *  $Id: Line2D.h 44313 2011-04-06 22:46:28Z agas $
00012  *******************************************************************************/
00013 
00014 #ifndef LINE2D_H
00015 #define LINE2D_H
00016 
00017 #include "vec2.h"
00018 #include "mat2.h"
00019 #include "Point2D.h"
00020 #include <vector>
00021 
00028 class Line2D
00029 {
00030 
00031   public:
00032 
00038     inline Line2D ( Point2D start, Point2D end )
00039     {
00040       m_Start = start;
00041       m_Vec = end-m_Start;
00042     }
00043 
00044 
00050     inline Line2D ( Point2D start,  CVec2 vec )
00051     {
00052       m_Start = start;
00053       m_Vec = vec;
00054     }
00055 
00059     inline ~Line2D() {}
00060 
00065     inline void setStart ( const Point2D start )
00066     {
00067       Point2D end = m_Start + m_Vec;
00068       m_Start = start;
00069       m_Vec = end-m_Start;
00070     }
00071 
00077     inline void setEnd ( const Point2D end )
00078     {
00079       m_Vec = end - m_Start;
00080     }
00081 
00086     inline Point2D start() const
00087     {
00088       return m_Start;
00089     }
00090 
00095     inline Point2D end() const
00096     {
00097       return m_Start + m_Vec;
00098     }
00099 
00104     inline CVec2 vec() const
00105     {
00106       return m_Vec;
00107     }
00108 
00109     inline bool operator== ( const Line2D& line ) const
00110     {
00111       return ( m_Start == line.start() && end() == line.end() );
00112     }
00113 
00118     float gradient() const ;
00119 
00124     inline float length() const {
00125       return m_Vec.magnitude();
00126     }
00127 
00133     inline float distance ( Point2D point ) const
00134     {
00135       Point2D pointOnLine = getRootPoint ( point );
00136       return ( point - pointOnLine ).magnitude();
00137     }
00138 
00143     inline void rotate ( float angle )
00144     {
00145       CMat2 rotMat = CMat2 ( angle );
00146       m_Start = rotMat * m_Start;
00147       m_Vec = rotMat * m_Vec;
00148     }
00149 
00157     inline Point2D getRootPoint ( Point2D point ) const
00158     {
00159       float t = ( point-m_Start ) * m_Vec;
00160       t /= m_Vec * m_Vec;
00161       Point2D pointOnLine = m_Start + ( t * m_Vec );
00162       return pointOnLine;
00163     }
00164 
00169     inline CVec2 getNormal() const {
00170       return m_Vec.getNormal()/m_Vec.magnitude();
00171     }
00172 
00181     Point2D getClosestPoint ( Point2D point ) const;
00182 
00189     Point2D getIntersectionPoint ( Line2D line ) const;
00190 
00197     float getIntersectionPointParameter ( Line2D line ) const;
00198 
00203     std::vector< Point2D > vertices ( unsigned substeps=0 );
00204 
00208     std::string toString() const;
00209 
00210   private:
00211 
00215     Point2D m_Start;
00216 
00220     CVec2 m_Vec;
00221 };
00222 
00223 #endif


robbie_architecture
Author(s): Viktor Seib
autogenerated on Mon Oct 6 2014 02:53:09