Go to the documentation of this file.00001 #ifndef OPENTISSUE_COLLISION_CONTINUOUS_CONTINUOUS_CONSERVATIVE_ADVANCEMENT_H
00002 #define OPENTISSUE_COLLISION_CONTINUOUS_CONTINUOUS_CONSERVATIVE_ADVANCEMENT_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 namespace OpenTissue
00013 {
00014 namespace collision
00015 {
00016 namespace continuous
00017 {
00018
00019
00047 template<typename transform_type, typename object_type1, typename object_type2, typename motion_policy>
00048 inline bool conservative_advancement(
00049 transform_type const & T_a
00050 , typename transform_type::vector3_type const & v_a
00051 , typename transform_type::vector3_type const & omega_a
00052 , object_type1 & A
00053 , typename transform_type::value_type const & r_max_a
00054 , transform_type const & T_b
00055 , typename transform_type::vector3_type const & v_b
00056 , typename transform_type::vector3_type const & omega_b
00057 , object_type2 & B
00058 , typename transform_type::value_type const & r_max_b
00059 , typename transform_type::vector3_type & p_a
00060 , typename transform_type::vector3_type & p_b
00061 , typename transform_type::value_type & time_of_impact
00062 , size_t & iterations
00063 , typename transform_type::value_type const & epsilon
00064 , typename transform_type::value_type const & max_tau
00065 , size_t const & max_iterations
00066 , motion_policy const &
00067 )
00068 {
00069 typedef typename transform_type::value_traits value_traits;
00070 typedef typename transform_type::vector3_type V;
00071 typedef typename transform_type::value_type T;
00072
00073 assert( r_max_a > value_traits::zero() || !"conservative_advancement(): maximum distance of object A must be positive");
00074 assert( r_max_b > value_traits::zero() || !"conservative_advancement(): maximum distance of object B must be positive");
00075 assert( max_tau > value_traits::zero() || !"conservative_advancement(): maximum time-step must be positive");
00076 assert( epsilon > value_traits::zero() || !"conservative_advancement(): collision envelope must be positive");
00077 assert( max_iterations > 0u || !"conservative_advancement(): maximum iterations must be positive");
00078
00079 T tau = value_traits::zero();
00080
00081 for(iterations=1u; iterations <= max_iterations; ++iterations)
00082 {
00083
00084 transform_type X_a = motion_policy::integrate_motion( T_a, tau, v_a, omega_a );
00085 transform_type X_b = motion_policy::integrate_motion( T_b, tau, v_b, omega_b );
00086
00087
00088 motion_policy::compute_closest_points( X_a, A, X_b, B, p_a, p_b );
00089
00090
00091 V v = p_a - p_b;
00092
00093 T min_distance = length(v);
00094
00095 if( min_distance <= epsilon )
00096 {
00097 time_of_impact = tau;
00098 return true;
00099 }
00100
00101 V n = unit( v );
00102
00103
00104
00105 T max_velocity = dot(v_b - v_a, n) + length(omega_a)*r_max_a + length(omega_b)*r_max_b;
00106
00107 if (max_velocity <= value_traits::zero() )
00108 return false;
00109
00110
00111 T delta_tau = min_distance / max_velocity;
00112 tau += delta_tau;
00113
00114 if ( tau > max_tau )
00115 return false;
00116 }
00117
00118
00119 return false;
00120 }
00121
00122
00123 }
00124 }
00125 }
00126
00127
00128 #endif