proj home

Files   Classes   Functions   Hierarchy  

particle Class Reference

A representation of a 2D particle. More...

#include <particle.h>

Collaboration diagram for particle:

List of all members.

Public Member Functions

 particle ()
 Stationary particle.
 particle (doublec p0, doublec p1, doublec v0, doublec v1, doublec r)
 Initialize a particle.
boolc isIntersecting (particle const &p2) const
 Do the two particles intersect?
void step (doublec t)
 Increment the particle in time.
void acczero ()
 Set the acceleration to zero.
ostreamprint (ostream &os) const
void collisionDynamics (particle &p2)
 Collision resolution.

Public Attributes

float radius
 The particles radius.
float pos [2]
 The particles position.
float vel [2]
 The particles velocity.
float acc [2]
 The particles acceleration.


Detailed Description

A representation of a 2D particle.

Definition at line 13 of file particle.h.


Constructor & Destructor Documentation

particle::particle (  )  [inline]

Stationary particle.

Definition at line 27 of file particle.h.

References acc, pos, and vel.

00028     : radius(0.0) { pos[0]=pos[1]=vel[0]=vel[1]=acc[0]=acc[1]=0.0; }

particle::particle ( doublec  p0,
doublec  p1,
doublec  v0,
doublec  v1,
doublec  r 
) [inline]

Initialize a particle.

Definition at line 32 of file particle.h.

References pos, radius, and vel.

00039     { pos[0]=p0; pos[1]=p1, vel[0]=v0; vel[1]=v1; radius=r; }


Member Function Documentation

void particle::acczero (  )  [inline]

Set the acceleration to zero.

Definition at line 60 of file particle.h.

References acc.

00061     { acc[0]=acc[1]=0.0; }

void particle::collisionDynamics ( particle p2  ) 

Collision resolution.

Definition at line 3 of file particle.cpp.

References pos, and vel.

Referenced by integration< D, F >::bruteforce().

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 }

boolc particle::isIntersecting ( particle const &  p2  )  const [inline]

Do the two particles intersect?

Definition at line 42 of file particle.h.

References pos, r, and radius.

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   }

ostream& particle::print ( ostream os  )  const [inline]

Definition at line 63 of file particle.h.

References acc, pos, radius, and vel.

Referenced by operator<<().

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   }

void particle::step ( doublec  t  )  [inline]

Increment the particle in time.

Definition at line 51 of file particle.h.

References acc, pos, and vel.

Referenced by integration< D, F >::bruteforce(), boxcollision::down(), boxcollision::left(), boxcollision::right(), integration< D, F >::uniformgridtest(), and boxcollision::up().

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   }


Member Data Documentation

float particle::acc[2]

The particles acceleration.

Definition at line 24 of file particle.h.

Referenced by acczero(), integration< D, F >::LJcalc(), particle(), print(), and step().

float particle::pos[2]

float particle::vel[2]


The documentation for this class was generated from the following files:

Generated on Fri Mar 4 00:50:08 2011 for Chelton Evans Source by  doxygen 1.5.8