Go to the documentation of this file.00001 #ifndef OPENTISSUE_COLLISION_GJK_GJK_SIGNED_DISTANCE_TO_EDGE_FACE_VORONOI_PLANE_H
00002 #define OPENTISSUE_COLLISION_GJK_GJK_SIGNED_DISTANCE_TO_EDGE_FACE_VORONOI_PLANE_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/math/math_is_number.h>
00013
00014 #include <cmath>
00015 #include <cassert>
00016
00017 namespace OpenTissue
00018 {
00019 namespace gjk
00020 {
00021 namespace detail
00022 {
00023
00038 template< typename V >
00039 inline typename V::value_type signed_distance_to_edge_face_voronoi_plane(
00040 V const & p
00041 , V const & A
00042 , V const & B
00043 , V const & C
00044 )
00045 {
00046 using std::fabs;
00047
00048 typedef typename V::value_traits value_traits;
00049 typedef typename V::value_type T;
00050
00051 V m = cross( A-C, B-C );
00052
00053 assert( dot( m, m ) > value_traits::zero() || !"signed_distance_to_edge_face_voronoi_plane(): Degenerate triangle encountered");
00054
00055 V l = cross( B-A, m );
00056 V n = unit( l );
00057
00058 T sign_p = dot( n, p-B );
00059 T sign_C = dot( n, C-B );
00060 T abs_p = fabs( sign_p );
00061
00062 assert( is_number( sign_p ) || !"signed_distance_to_edge_face_voronoi_plane(): Not a Number encountered");
00063 assert( is_number( sign_C ) || !"signed_distance_to_edge_face_voronoi_plane(): Not a Number encountered");
00064 assert( is_number( abs_p ) || !"signed_distance_to_edge_face_voronoi_plane(): Not a Number encountered");
00065
00066 bool in_front = ( (sign_p*sign_C) <= value_traits::zero() );
00067
00068 return in_front ? abs_p : -abs_p;
00069 }
00070
00071 }
00072
00073 }
00074
00075 }
00076
00077
00078 #endif