proj home

Files   Classes   Functions   Hierarchy  

particle.h

Go to the documentation of this file.
00001 #ifndef PARTICLE_H
00002 #define PARTICLE_H
00003 
00004 #include <iostream>
00005 #include <cmath>
00006 using namespace std;
00007 
00008 #include <typedefs.h>
00009 
00013 class particle
00014 {
00015 public:
00016 
00018   float radius;
00020   float pos[2];
00022   float vel[2];
00024   float acc[2];
00025 
00027   particle()
00028     : radius(0.0) { pos[0]=pos[1]=vel[0]=vel[1]=acc[0]=acc[1]=0.0; }
00029 
00031   particle
00032   (
00033     doublec p0,
00034     doublec p1,
00035     doublec v0,
00036     doublec v1,
00037     doublec r
00038   )
00039     { pos[0]=p0; pos[1]=p1, vel[0]=v0; vel[1]=v1; radius=r; }
00040 
00042   boolc isIntersecting( particle const & p2 ) const
00043   {
00044     doublec dy(p2.pos[1]-pos[1]);
00045     doublec dx(p2.pos[0]-pos[0]);
00046     doublec r(radius+p2.radius);
00047     return dy*dy+dx*dx < r*r;
00048   }
00049 
00051   void step(doublec t)
00052   {
00053     vel[0] += t*acc[0];
00054     vel[1] += t*acc[1];
00055     pos[0] += t*vel[0];
00056     pos[1] += t*vel[1];
00057   }
00058 
00060   void acczero()
00061     { acc[0]=acc[1]=0.0; }
00062 
00063   ostream & print(ostream & os) const
00064   {
00065     os << pos[0] << " " << pos[1] << " ";
00066     os << vel[0] << " " << vel[1] << " ";
00067     os << acc[0] << " " << acc[1] << " ";
00068     os << radius;
00069     return os;
00070   }
00071 
00072 /*
00073 NOTE:  
00074   This code is to be directly put in and
00075   not called because there is a large
00076   penalty in calling it. Cache thrashing
00077   as a result of OO method call.
00078 
00079   boolc collision
00080   (
00081     particle & p2,
00082     doublec h
00083   )
00084 
00085   {
00086     if (isIntersecting(p2))
00087     {
00088       step(-h);
00089       p2.step(-h);
00090       collisionDynamics(p2);
00091       step(h);
00092       p2.step(h);
00093 
00094       return true;
00095     }
00096 
00097     return false;
00098   }
00099 */
00100 
00102   void collisionDynamics(particle & p2);
00103 };
00104 
00105 
00106 ostream & operator << (ostream & os, particle const & p);
00107 
00108 
00109 #endif
00110 
00111 

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