00001 // -*-c++-*- 00002 00008 /* 00009 *Copyright: 00010 00011 Copyright (C) Hidehisa Akiyama 00012 00013 This code is free software; you can redistribute it and/or 00014 modify it under the terms of the GNU Lesser General Public 00015 License as published by the Free Software Foundation; either 00016 version 2.1 of the License, or (at your option) any later version. 00017 00018 This library is distributed in the hope that it will be useful, 00019 but WITHOUT ANY WARRANTY; without even the implied warranty of 00020 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00021 Lesser General Public License for more details. 00022 00023 You should have received a copy of the GNU Lesser General Public 00024 License along with this library; if not, write to the Free Software 00025 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00026 00027 *EndCopyright: 00028 */ 00029 00031 00032 #ifndef RCSC_GEOM_RAY2D_H 00033 #define RCSC_GEOM_RAY2D_H 00034 00035 #include <rcsc/geom/line_2d.h> 00036 #include <rcsc/geom/vector_2d.h> 00037 00038 #include <iostream> 00039 #include <cmath> 00040 00041 namespace rcsc { 00042 00047 class Ray2D { 00048 private: 00050 Vector2D M_origin; 00052 AngleDeg M_direction; 00053 00054 public: 00058 Ray2D() 00059 : M_origin( 0.0, 0.0 ) 00060 , M_direction( 0.0 ) 00061 { } 00062 00068 Ray2D( const Vector2D & origin, 00069 const AngleDeg & direction ) 00070 : M_origin( origin ) 00071 , M_direction( direction ) 00072 { } 00078 Ray2D( const Vector2D & origin, 00079 const Vector2D & dir_point ) 00080 : M_origin( origin ) 00081 , M_direction( ( dir_point - origin ).th() ) 00082 { } 00083 00088 const 00089 Vector2D & origin() const 00090 { 00091 return M_origin; 00092 } 00093 00098 const 00099 AngleDeg & dir() const 00100 { 00101 return M_direction; 00102 } 00103 00108 Line2D line() const 00109 { 00110 return Line2D( origin(), dir() ); 00111 } 00112 00119 bool inRightDir( const Vector2D & point, 00120 const double & thr = 10.0 ) const 00121 { 00122 return ( ( point - origin() ).th() - dir() ).abs() < thr; 00123 } 00124 00131 Vector2D intersection( const Line2D & other ) const; 00132 00139 Vector2D intersection( const Ray2D & other ) const; 00140 00141 }; 00142 00143 } 00144 00145 #endif