Go to the documentation of this file.00001 #ifndef OPENTISSUE_DYNAMICS_MBD_UTIL_COLLISION_LAWS_MBD_NEWTON_COLLISION_LAW_POLICY_H
00002 #define OPENTISSUE_DYNAMICS_MBD_UTIL_COLLISION_LAWS_MBD_NEWTON_COLLISION_LAW_POLICY_H
00003
00004
00005
00006
00007 #include <OpenTissue/configuration.h>
00008
00009 #include <OpenTissue/dynamics/mbd/mbd_compute_collision_matrix.h>
00010 #include <OpenTissue/dynamics/mbd/mbd_compute_relative_contact_velocity.h>
00011
00012 namespace OpenTissue
00013 {
00014 namespace mbd
00015 {
00016 namespace collision_laws
00017 {
00018
00032 template<typename contact_type>
00033 typename contact_type::vector3_type
00034 compute_newton_impulse(contact_type const * contact)
00035 {
00036 typedef typename contact_type::body_type body_type;
00037 typedef typename contact_type::material_type material_type;
00038 typedef typename contact_type::real_type real_type;
00039 typedef typename contact_type::vector3_type vector3_type;
00040 typedef typename body_type::matrix3x3_type matrix3x3_type;
00041 typedef typename body_type::value_traits value_traits;
00042
00043
00044
00045
00046
00047
00048 material_type * material = contact->m_material;
00049 body_type * A = contact->get_body_A();
00050 body_type * B = contact->get_body_B();
00051 real_type e_n = material->normal_restitution();
00052 vector3_type v_a,v_b,w_a,w_b,r_a,r_b;
00053 A->get_velocity(v_a);
00054 A->get_spin(w_a);
00055 r_a = contact->m_rA;
00056 B->get_velocity(v_b);
00057 B->get_spin(w_b);
00058 r_b = contact->m_rB;
00059 vector3_type u = mbd::compute_relative_contact_velocity(v_a,w_a,r_a,v_b,w_b,r_b);
00060 real_type u_before = u * contact->m_n;
00061 if(u_before>=value_traits::zero())
00062 return vector3_type(value_traits::zero(),value_traits::zero(),value_traits::zero());
00063 real_type inv_m_a = A->get_inverse_mass();
00064 real_type inv_m_b = B->get_inverse_mass();
00065 matrix3x3_type invI_a,invI_b;
00066 A->get_inverse_inertia_wcs(invI_a);
00067 B->get_inverse_inertia_wcs(invI_b);
00068 matrix3x3_type K = mbd::compute_collision_matrix(inv_m_a,invI_a,r_a,inv_m_b,invI_b,r_b);
00069 vector3_type J = K * contact->m_n;
00070 real_type nKn = contact->m_n * J;
00071 real_type minus_1_en_u_before = -(1.+e_n)*u_before;
00072 J = contact->m_n*(minus_1_en_u_before/nKn);
00073
00074 return J;
00075 }
00076
00077 class NewtonCollisionLawPolicy
00078 {
00079 public:
00080 template<typename contact_type>
00081 typename contact_type::vector3_type compute_impulse(contact_type const * contact) const
00082 {
00083 return compute_newton_impulse(contact);
00084 }
00085 };
00086
00087 }
00088 }
00089 }
00090
00091 #endif