Go to the documentation of this file.00001 #ifndef OPENTISSUE_COLLISION_COLLISION_SPHERE_SPHERE_H
00002 #define OPENTISSUE_COLLISION_COLLISION_SPHERE_SPHERE_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 namespace OpenTissue
00013 {
00014 namespace collision
00015 {
00016
00031 template< typename vector3_type, typename real_type>
00032 bool sphere_sphere(
00033 vector3_type const & cA
00034 , real_type const & rA
00035 , vector3_type const & cB
00036 , real_type const & rB
00037 , real_type const & envelope
00038 , vector3_type & p
00039 , vector3_type & n
00040 , real_type & distance
00041 )
00042 {
00043
00044 vector3_type diff = cB - cA;
00045 real_type radius_sum = rA + rB;
00046
00047
00048
00049
00050
00051
00052 real_type squared_radius_sum_plus_envelope = radius_sum + envelope;
00053 squared_radius_sum_plus_envelope *= squared_radius_sum_plus_envelope;
00054 real_type squared_distance = diff*diff;
00055 if(squared_distance > squared_radius_sum_plus_envelope)
00056 return false;
00057
00058
00059
00060
00061 n = diff;
00062 real_type length = sqrt(squared_distance);
00063 n /= length;
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085 real_type dB = (length / ( (rA/rB) + 1.0));
00086 real_type dA = length - dB;
00087 distance = length - radius_sum;
00088 p = n*dA + cA;
00089 return true;
00090 }
00091
00092 }
00093
00094 }
00095
00096
00097 #endif