proj home

Files   Classes   Functions   Hierarchy  

boxcollision Class Reference

Define a primitive Axis aligned bounding box. More...

#include <boxcollision.h>

Collaboration diagram for boxcollision:

List of all members.

Public Member Functions

 boxcollision (doublec x0_, doublec x1_, doublec y0_, doublec y1_)
 Construct rectangular region.
boolc left (particle &p, doublec h) const
 Test for collision with the left wall, if there is a collision then resolve the collision.
boolc right (particle &p, doublec h) const
 Test for collision with the right wall, if there is a collision then resolve the collision.
boolc up (particle &p, doublec h) const
 Test for collision with the top wall, if there is a collision then resolve the collision.
boolc down (particle &p, doublec h) const
 Test for collision with the below wall, if there is a collision then resolve the collision.
boolc walls (particle &p, doublec h) const
 Resolve any collision the particle has with the walls.
ostreamprint (ostream &os) const
 Print the bounding box.

Public Attributes

double x0
 The left wall.
double x1
 The right wall.
double y0
 The below wall.
double y1
 The above wall.


Detailed Description

Define a primitive Axis aligned bounding box.

The particles are assumed to be inside the box. If a collision is detected, the particle's path is reversed and the particle is bounced off the wall. Assuming that the particles previous initial position was valid.

Definition at line 18 of file boxcollision.h.


Constructor & Destructor Documentation

boxcollision::boxcollision ( doublec  x0_,
doublec  x1_,
doublec  y0_,
doublec  y1_ 
) [inline]

Construct rectangular region.

Definition at line 34 of file boxcollision.h.

00040     : x0(x0_), x1(x1_), y0(y0_), y1(y1_) {}


Member Function Documentation

boolc boxcollision::down ( particle p,
doublec  h 
) const

Test for collision with the below wall, if there is a collision then resolve the collision.

Definition at line 83 of file boxcollision.cpp.

References particle::pos, particle::radius, SHOW, particle::step(), particle::vel, and y0.

Referenced by walls().

00084 {
00085   assert(h>0.0);
00086 
00087   if ( y0+p.radius < p.pos[1] )
00088     return false;
00089 
00090   p.step(-h);
00091 
00092   assert(p.vel[1]!=0.0);
00093   doublec t1 = 
00094     (y0+p.radius-p.pos[1])/p.vel[1];
00095   doublec t2 = h-t1;
00096 
00097 #ifdef DEGUG_BOX
00098 if ((t1>0.0)==false)
00099 {
00100   cout << SHOW(t1) << " " << SHOW(t2) << " " << SHOW(h) << endl;
00101 }
00102 #endif
00103 
00104   p.step(t1-h);
00105 
00106   p.vel[1]*=-1.0;
00107   p.step(t2);
00108 
00109   return true;
00110 }

boolc boxcollision::left ( particle p,
doublec  h 
) const

Test for collision with the left wall, if there is a collision then resolve the collision.

Definition at line 17 of file boxcollision.cpp.

References particle::pos, particle::radius, particle::step(), particle::vel, and x0.

Referenced by walls().

00018 {
00019   assert(h>0.0);
00020 
00021   if ( x0 < p.pos[0]-p.radius )
00022     return false;
00023 
00024   p.step(-h);
00025 
00026   assert(p.vel[0]!=0.0);
00027   doublec t1 = 
00028     (x0+p.radius-p.pos[0])/p.vel[0];
00029   doublec t2 = h-t1;
00030 
00031   p.step(t1-h);
00032 
00033   p.vel[0]*=-1.0;
00034   p.step(t2);
00035 
00036   return true;
00037 }

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

Print the bounding box.

Definition at line 71 of file boxcollision.h.

References x0, x1, y0, and y1.

00072     { os << "x0=" << x0 << " x1=" << x1;
00073       return os << " y0=" << y0 << " y1=" << y1; }

boolc boxcollision::right ( particle p,
doublec  h 
) const

Test for collision with the right wall, if there is a collision then resolve the collision.

Definition at line 39 of file boxcollision.cpp.

References particle::pos, particle::radius, particle::step(), particle::vel, and x1.

Referenced by walls().

00040 {
00041   assert(h>0.0);
00042 
00043   if ( p.pos[0] < x1-p.radius )
00044     return false;
00045 
00046   p.step(-h);
00047 
00048   assert(p.vel[0]!=0.0);
00049   doublec t1 = 
00050     (x1-p.radius-p.pos[0])/p.vel[0];
00051   doublec t2 = h-t1;
00052 
00053   p.step(t1-h);
00054 
00055   p.vel[0]*=-1.0;
00056   p.step(t2);
00057 
00058   return true;
00059 }

boolc boxcollision::up ( particle p,
doublec  h 
) const

Test for collision with the top wall, if there is a collision then resolve the collision.

Definition at line 61 of file boxcollision.cpp.

References particle::pos, particle::radius, particle::step(), particle::vel, and y1.

Referenced by walls().

00062 {
00063   assert(h>0.0);
00064 
00065   if ( p.pos[1] < y1-p.radius )
00066     return false;
00067 
00068   p.step(-h);
00069 
00070   assert(p.vel[1]!=0.0);
00071   doublec t1 = 
00072     (y1-p.radius-p.pos[1])/p.vel[1];
00073   doublec t2 = h-t1;
00074 
00075   p.step(t1-h);
00076 
00077   p.vel[1]*=-1.0;
00078   p.step(t2);
00079 
00080   return true;
00081 }

boolc boxcollision::walls ( particle p,
doublec  h 
) const [inline]

Resolve any collision the particle has with the walls.

Definition at line 56 of file boxcollision.h.

References down(), left(), right(), and up().

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

00057   {
00058     if (left(p,h))
00059       return true;
00060     if (right(p,h))
00061       return true;
00062     if (up(p,h))
00063       return true;
00064     if (down(p,h))
00065       return true;
00066 
00067     return false;
00068   }


Member Data Documentation

The right wall.

Definition at line 26 of file boxcollision.h.

Referenced by particlev0spaced::eval(), print(), particledistribution::randomposition(), d2toindex::reset(), and right().

The above wall.

Definition at line 30 of file boxcollision.h.

Referenced by particlev0spaced::eval(), print(), particledistribution::randomposition(), d2toindex::reset(), and up().


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

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