Go to the documentation of this file.00001 #ifndef OPENTISSUE_COLLISION_INTERSECT_INTERSECT_LINE_SPHERE_H
00002 #define OPENTISSUE_COLLISION_INTERSECT_INTERSECT_LINE_SPHERE_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 namespace OpenTissue
00013 {
00014 namespace intersect
00015 {
00016
00026 template<typename vector3_type, typename sphere_type>
00027 bool line_sphere(vector3_type const & b, vector3_type const & e, sphere_type const & sphere)
00028 {
00029 typedef typename vector3_type::value_type real_type;
00030
00031 vector3_type c = sphere.center();
00032 real_type r2 = sphere.squared_radius();
00033
00034 vector3_type eb = e-b;
00035 vector3_type cb = c-b;
00036 real_type t = (cb*eb) / (eb*eb);
00037 if(t<0 || t>1.0)
00038 return false;
00039
00040
00041
00042 vector3_type pc = eb*t - cb;
00043 if ( (pc*pc) <= r2 )
00044 return true;
00045 return false;
00046 }
00047
00048 }
00049
00050 }
00051
00052
00053 #endif