proj home

Files   Classes   Functions   Hierarchy  

particle.cpp

Go to the documentation of this file.
00001 #include <particle.h>
00002 
00003 void particle::collisionDynamics(particle &p2)
00004 {
00005   float n[2], t[2], n_mag, n_mag_sq;
00006   float vi_nt[2], vj_nt[2], tmp;
00007 
00008   /* Normal vector between centres. */
00009   n[0] = p2.pos[0] - pos[0];
00010   n[1] = p2.pos[1] - pos[1];
00011   
00012   /* Normalise normal vector. */
00013   n_mag_sq = n[0] * n[0] + n[1] * n[1];
00014   n_mag = sqrt(n_mag_sq);
00015   n[0] /= n_mag;
00016   n[1] /= n_mag;
00017 
00018   /* Tangent vector. */
00019   t[0] = -n[1];
00020   t[1] = n[0];
00021 
00022   /* 
00023    * Resolve particle velocities into components in the 
00024    * normal and tangential direction. 
00025    */
00026   vi_nt[0] = p2.vel[0] * n[0] + p2.vel[1] * n[1];
00027   vi_nt[1] = p2.vel[0] * t[0] + p2.vel[1] * t[1];
00028   vj_nt[0] = vel[0] * n[0] + vel[1] * n[1];
00029   vj_nt[1] = vel[0] * t[0] + vel[1] * t[1];
00030 
00031   /* Interchange particle velocities along normal direction. */
00032   tmp = vi_nt[0];
00033   vi_nt[0] = vj_nt[0];
00034   vj_nt[0] = tmp;
00035 
00036   /* Resolve back. */
00037   p2.vel[0] = vi_nt[0] * n[0] + vi_nt[1] * t[0];
00038   p2.vel[1] = vi_nt[0] * n[1] + vi_nt[1] * t[1];
00039   vel[0] = vj_nt[0] * n[0] + vj_nt[1] * t[0];
00040   vel[1] = vj_nt[0] * n[1] + vj_nt[1] * t[1];
00041 
00042 }
00043 
00044 ostream & operator << (ostream & os, particle const & p)
00045 {
00046   return p.print(os);
00047 }
00048 

Generated on Fri Mar 4 00:49:29 2011 for Chelton Evans Source by  doxygen 1.5.8