Go to the documentation of this file.00001 #ifndef OPENTISSUE_COLLISION_INTERSECT_INTERSECT_POINT_TRIANGLE_H
00002 #define OPENTISSUE_COLLISION_INTERSECT_INTERSECT_POINT_TRIANGLE_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/math/math_precision.h>
00013 #include <OpenTissue/core/geometry/geometry_barycentric.h>
00014 #include <OpenTissue/core/geometry/geometry_plane.h>
00015
00016 namespace OpenTissue
00017 {
00018 namespace intersect
00019 {
00020
00033 template<typename vector3_type,typename triangle_type>
00034 bool point_triangle(vector3_type const & p, triangle_type const & triangle)
00035 {
00036 typedef typename triangle_type::math_types math_types;
00037 typedef typename math_types::real_type real_type;
00038
00039
00040 static const real_type threshold = math::working_precision<real_type>();
00041 static const real_type lower = -threshold;
00042 static const real_type upper = 1.+threshold;
00043 OpenTissue::geometry::Plane<math_types> plane(triangle.p0(),triangle.p1(),triangle.p2());
00044
00045 real_type d = plane.signed_distance(p);
00046 if(d > threshold || d < -threshold)
00047 return false;
00048 real_type w1,w2,w3;
00049 OpenTissue::geometry::barycentric_algebraic(triangle.p0(),triangle.p1(),triangle.p2(),p,w1,w2,w3);
00050 if(
00051 (w1>lower)&&(w1<upper)
00052 &&
00053 (w2>lower)&&(w2<upper)
00054 &&
00055 (w3>lower)&&(w3<upper)
00056 )
00057 {
00058 return true;
00059 }
00060 return false;
00061 }
00062
00063 }
00064
00065 }
00066
00067
00068 #endif