Go to the documentation of this file.00001 #ifndef OPENTISSUE_COLLISION_CONTINUOUS_CONTINUOUS_DEFAULT_MOTION_POLICY_H
00002 #define OPENTISSUE_COLLISION_CONTINUOUS_CONTINUOUS_DEFAULT_MOTION_POLICY_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/math/math_is_number.h>
00013 #include <OpenTissue/core/math/math_functions.h>
00014 #include <OpenTissue/collision/gjk/gjk_compute_closest_points.h>
00015
00016 #include <cmath>
00017 #include <cassert>
00018
00019 namespace OpenTissue
00020 {
00021 namespace collision
00022 {
00023 namespace continuous
00024 {
00025
00036 class DefaultMotionPolicy
00037 {
00038 public:
00039
00054 template< typename transform_type >
00055 static void compute_velocities(
00056 transform_type const & T_from
00057 , transform_type const & T_to
00058 , typename transform_type::value_type const & delta_tau
00059 , typename transform_type::vector3_type & v
00060 , typename transform_type::vector3_type & omega
00061 )
00062 {
00063 using std::atan2;
00064
00065 typedef typename transform_type::value_traits value_traits;
00066 typedef typename transform_type::vector3_type V;
00067 typedef typename transform_type::value_type T;
00068
00069 assert( delta_tau > value_traits::zero() || !"compute_velocities(): time step must be positive");
00070
00071
00072 v = (T_to.T() - T_from.T()) / delta_tau;
00073
00074 T theta;
00075 V n;
00076 get_axis_angle(
00077 prod( T_to.Q(), conj( T_from.Q() ) )
00078 , n
00079 , theta
00080 );
00081 omega = (theta/ delta_tau)*n;
00082 }
00083
00094 template< typename transform_type>
00095 static transform_type integrate_motion(
00096 transform_type const & X
00097 , typename transform_type::value_type const & tau
00098 , typename transform_type::vector3_type const & v
00099 , typename transform_type::vector3_type const & omega)
00100 {
00101 typedef typename transform_type::value_traits value_traits;
00102 typedef typename transform_type::vector3_type V;
00103 typedef typename transform_type::quaternion_type Q;
00104 typedef typename transform_type::value_type T;
00105
00106 assert( tau >= value_traits::zero() || !"integrate_motion(): Tau must be non-negative");
00107
00108 T const radian = tau * length( omega );
00109 V const axis = unit( omega );
00110
00111 assert( is_number( radian ) || !"integrate_motion(): NaN encountered");
00112 assert( is_number( axis(0) ) || !"integrate_motion(): NaN encountered");
00113 assert( is_number( axis(1) ) || !"integrate_motion(): NaN encountered");
00114 assert( is_number( axis(2) ) || !"integrate_motion(): NaN encountered");
00115
00116 Q dq;
00117 V dv;
00118 dq.Ru( radian, axis);
00119 dv = v*tau;
00120
00121 assert( is_number( dv(0) ) || !"integrate_motion(): NaN encountered");
00122 assert( is_number( dv(1) ) || !"integrate_motion(): NaN encountered");
00123 assert( is_number( dv(2) ) || !"integrate_motion(): NaN encountered");
00124
00125 return transform_type( dv + X.T(), prod(dq, X.Q()) );
00126 }
00127
00138 template< typename transform_type, typename object_type1, typename object_type2>
00139 static void compute_closest_points(
00140 transform_type const & X_a
00141 , object_type1 const & A
00142 , transform_type const & X_b
00143 , object_type2 const & B
00144 , typename transform_type::vector3_type & p_a
00145 , typename transform_type::vector3_type & p_b
00146 )
00147 {
00148 typedef typename transform_type::value_traits value_traits;
00149 typedef typename transform_type::value_type T;
00150
00151
00152
00153 OpenTissue::gjk::VoronoiSimplexSolverPolicy const simplex_solver_policy = OpenTissue::gjk::VoronoiSimplexSolverPolicy();
00154
00155 size_t const max_iterations = 100u;
00156 T const absolute_tolerance = boost::numeric_cast<T>(10e-6);
00157 T const relative_tolerance = boost::numeric_cast<T>(10e-6);
00158 T const stagnation_tolerance = boost::numeric_cast<T>(10e-15);
00159 size_t iterations = 0u;
00160 size_t status = 0u;
00161 T distance = value_traits::infinity();
00162
00163 OpenTissue::gjk::compute_closest_points(
00164 X_a
00165 , A
00166 , X_b
00167 , B
00168 , p_a
00169 , p_b
00170 , distance
00171 , iterations
00172 , status
00173 , absolute_tolerance
00174 , relative_tolerance
00175 , stagnation_tolerance
00176 , max_iterations
00177 , simplex_solver_policy
00178 );
00179
00180 }
00181
00182 };
00183
00184 }
00185 }
00186 }
00187
00188
00189 #endif