Go to the documentation of this file.00001 #ifndef OPENTISSUE_COLLISION_INTERSECT_INTERSECT_LINE_PLANE_H
00002 #define OPENTISSUE_COLLISION_INTERSECT_INTERSECT_LINE_PLANE_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/math/math_vector3.h>
00013 #include <OpenTissue/core/math/math_precision.h>
00014
00015 #include <list>
00016 #include <string>
00017 #include <cmath>
00018 #include <iostream>
00019 #include <sstream>
00020
00021 namespace OpenTissue
00022 {
00023
00024 namespace intersect
00025 {
00026
00038 template<typename vector3_type,typename plane_type,typename real_type>
00039 bool line_plane(vector3_type const & O,vector3_type const & D,plane_type const & plane, vector3_type & u,real_type & t)
00040 {
00041 real_type dO = plane.signed_distance(O);
00042 real_type dD = plane.signed_distance(D);
00043 t = dO/(dO-dD);
00044 u = (D - O)*t + O;
00045 if(dO>0 && dD>0)
00046 return false;
00047 if(dO<0 && dD<0)
00048 return false;
00049 return true;
00050 }
00051
00052
00065 template<typename vector3_type,typename plane_type>
00066 bool line_plane(vector3_type const & O,vector3_type const & D,plane_type const & plane,vector3_type & u)
00067 {
00068 typename vector3_type::value_type t;
00069 return line_plane(O,D,plane,u,t);
00070 }
00071
00080 template<typename vector3_type,typename plane_type>
00081 vector3_type line_plane(vector3_type const & v0,vector3_type const & v1,plane_type const & plane)
00082 {
00083 typename vector3_type::value_type s0 = plane.signed_distance(v0);
00084 typename vector3_type::value_type s1 = plane.signed_distance(v1);
00085 typename vector3_type::value_type s = s0/(s0-s1);
00086 return ((v1 - v0)*s + v0);
00087 }
00088
00089 }
00090
00091 }
00092
00093
00094 #endif