Go to the documentation of this file.00001 #ifndef OPENTISSUE_DYNAMICS_PSYS_COLLISION_COLLISION_PSYS_SPHERE_H
00002 #define OPENTISSUE_DYNAMICS_PSYS_COLLISION_COLLISION_PSYS_SPHERE_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <cassert>
00013 #include <cmath>
00014
00015 namespace OpenTissue
00016 {
00017 namespace psys
00018 {
00019
00023 template<typename particle_system_type, typename sphere_type, typename contact_point_container>
00024 void collision_psys_sphere(
00025 particle_system_type & system
00026 , sphere_type const & sphere
00027 , contact_point_container & contacts
00028 )
00029 {
00030 typedef typename particle_system_type::real_type real_type;
00031 typedef typename particle_system_type::vector3_type vector3_type;
00032 typedef typename contact_point_container::value_type contact_point_type;
00033 typedef typename particle_system_type::particle_iterator particle_iterator;
00034
00035 real_type r = sphere.radius();
00036 real_type r2 = sphere.squared_radius();
00037 vector3_type center = sphere.center();
00038
00039 particle_iterator p = system.particle_begin();
00040 particle_iterator end = system.particle_end();
00041 for(;p!=end;++p)
00042 {
00043 vector3_type pos = p->position();
00044 vector3_type diff = pos - center;
00045 real_type d2 = diff * diff;
00046 if(d2<r2)
00047 {
00048 contact_point_type cp;
00049 cp.m_A0 = &(*p);
00050 cp.m_a0 = real_type();
00051 cp.m_p = pos;
00052 cp.m_n = unit(diff);
00053 real_type d = std::sqrt(d2);
00054 cp.m_distance = r - d;
00055 contacts.push_back(cp);
00056 }
00057 }
00058 }
00059
00060 }
00061 }
00062
00063
00064 #endif