MC_sphere_physic.cpp

Go to the documentation of this file.
00001 
00002 
00003 #include <MC_sphere_physic.hpp>
00004 
00005 namespace mesh_conv
00006 {
00007     MC_sphere_physic::MC_sphere_physic()
00008             :MC_sphere_geometry(),speed_internal(MC_v3d(0,0,0)),force_internal(MC_v3d(0,0,0)),mass_internal(1),damping_factor_internal(0.01)
00009     {}
00010     MC_sphere_physic::MC_sphere_physic(const MC_v3d& position,const double& radius)
00011             :MC_sphere_geometry(position,radius),speed_internal(MC_v3d(0,0,0)),force_internal(MC_v3d(0,0,0)),mass_internal(1),damping_factor_internal(0.01)
00012     {}
00013     MC_sphere_physic::MC_sphere_physic(const MC_v3d& position,const double& radius,const MC_v3d& speed_init)
00014             :MC_sphere_geometry(position,radius),speed_internal(speed_init),force_internal(MC_v3d(0,0,0)),mass_internal(1),damping_factor_internal(0.01)
00015     {}
00016 
00017 
00018     MC_v3d& MC_sphere_physic::speed()
00019     {return speed_internal;}
00020     const MC_v3d& MC_sphere_physic::speed() const
00021     {return speed_internal;}
00022     MC_v3d& MC_sphere_physic::force()
00023     {return force_internal;}
00024     const MC_v3d& MC_sphere_physic::force() const
00025     {return force_internal;}
00026 
00027     double& MC_sphere_physic::mass(){return mass_internal;}
00028     const double& MC_sphere_physic::mass() const{return mass_internal;}
00029 
00030     double& MC_sphere_physic::damping_factor(){return damping_factor_internal;}
00031     const double& MC_sphere_physic::damping_factor() const{return damping_factor_internal;}
00032 
00033     void MC_sphere_physic::evolve(const double& delta_t)
00034     {
00035 
00036         MC_v3d acceleration = force_internal/mass_internal;
00037 
00038         //explicit integation
00039         speed_internal = (1-damping_factor_internal)*speed_internal + delta_t*acceleration;
00040         center() += delta_t*speed_internal;
00041 
00042         //force_internal.set_zero();
00043     }
00044 
00045     void MC_sphere_physic::constraint_in_unit_cube()
00046     {
00047 
00048         MC_v3d& c=center();
00049         MC_v3d& s=speed();
00050 
00051         const double& r=radius();
00052 
00053         // ********************** //
00054 
00055         // TO DO :
00056 
00057         // si la sphere sort de [0,1] alors on change la vitesse s
00058 
00059         // ********************** //
00060 
00061 
00062     }
00063 
00064     void MC_sphere_physic::constraint_no_collision_sphere(MC_sphere_physic* sphere_1,MC_sphere_physic* sphere_2)
00065     {
00066 
00067         if(! (sphere_1->is_collide(*sphere_2)) )
00068             return;
00069 
00070         const MC_v3d& c1=sphere_1->center();
00071         const MC_v3d& c2=sphere_2->center();
00072 
00073         const double& r1=sphere_1->radius();
00074         const double& r2=sphere_2->radius();
00075 
00076         double L=(c1-c2).norm();
00077         MC_v3d u=(c1-c2)/L;
00078 
00079         double r_total=(r1+r2);
00080         double L_penetration=r_total-L;
00081 
00082         double epsilon=1e-5;
00083 
00084         //project on the contact surface
00085         sphere_1->center() += +(L_penetration+epsilon)/2.0 * u;
00086         sphere_2->center() += -(L_penetration+epsilon)/2.0 * u;
00087 
00088 
00089 
00090         // ********************** //
00091         // TO DO :
00092 
00093         // changer la vitesse
00094         MC_v3d nouvelle_vitesse_1=sphere_1->speed();
00095         MC_v3d nouvelle_vitesse_2=sphere_1->speed();
00096         // ********************** //
00097 
00098 
00099         sphere_1->speed()=nouvelle_vitesse_1;
00100         sphere_2->speed()=nouvelle_vitesse_2;
00101 
00102     }
00103 
00104 }

Generated on Sun Apr 18 20:24:47 2010 by  doxygen 1.6.1