00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef SGE_RAY2_HPP_INCLUDED
00022 #define SGE_RAY2_HPP_INCLUDED
00023
00024 #include "vector.hpp"
00025 #include "solve2.hpp"
00026 #include "line_seg2.hpp"
00027
00028 namespace sge
00029 {
00030
00031 template<typename T> class basic_ray2 {
00032 public:
00033 typedef math::basic_vector<T,2> vec;
00034 basic_ray2(vec o, vec d) : o(o), d(d) {}
00035 bool intersection(const basic_line_seg2<T>& r, vec& v) const
00036 {
00037 T x1,x2;
00038 if(!solve2(d.x,d.y,-r.d.x,-r.d.y,r.p.x-o.x,r.p.y-o.y,x1,x2))
00039 return false;
00040 if(x1 < 0 || x2 < 0 || x2 > 1)
00041 return false;
00042 v = vec(o.x + x1*d.x, o.y + x1*d.y);
00043 return true;
00044 }
00045 private:
00046 vec o,d;
00047 };
00048
00049 template<typename T> inline bool intersection(const basic_ray2<T>& l, const basic_line_seg2<T>& r, typename basic_ray2<T>::vec& v)
00050 {
00051 return l.intersection(r,v);
00052 }
00053
00054 }
00055
00056 #endif