Go to the documentation of this file.00001 #ifndef OPENTISSUE_COLLISION_COLLISION_SPHERE_PLANE_H
00002 #define OPENTISSUE_COLLISION_COLLISION_SPHERE_PLANE_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/math/math_constants.h>
00013
00014 #include <OpenTissue/core/math/math_precision.h>
00015
00016 namespace OpenTissue
00017 {
00018 namespace collision
00019 {
00020
00035 template<typename coordsys_type,typename sphere_type,typename plane_type,typename real_type,typename vector3_type>
00036 bool sphere_plane(
00037 coordsys_type const & StoWCS
00038 , coordsys_type const & PtoWCS
00039 , sphere_type const & sphere
00040 , plane_type const & plane
00041 , real_type const & envelope
00042 , vector3_type & p
00043 , vector3_type & n
00044 , real_type & distance
00045 )
00046 {
00047
00048
00049
00050 coordsys_type StoP = model_update(StoWCS,PtoWCS);
00051
00052
00053 p = sphere.center();
00054 real_type r = sphere.radius();
00055
00056
00057 StoP.xform_point(p);
00058
00059
00060
00061
00062 distance = plane.signed_distance(p);
00063 if(distance>(envelope+r))
00064 return false;
00065
00066
00067 n = plane.n();
00068
00069
00070
00071 p = p - n*distance;
00072
00073
00074
00075
00076 distance -= r;
00077
00078
00079
00080 PtoWCS.xform_point(p);
00081 PtoWCS.xform_vector(n);
00082 return true;
00083 }
00084
00085 }
00086 }
00087
00088
00089 #endif