Space Comps
 All Classes Files Functions Variables
Public Member Functions | List of all members
SweepNPruneAlgorithmSimple Class Reference

The SweepNPruneAlgorithmSimple class executes the sweep and prune method of collision detection. More...

#include <sweepnprunealgorithmsimple.h>

Inheritance diagram for SweepNPruneAlgorithmSimple:
Algorithm

Public Member Functions

 SweepNPruneAlgorithmSimple (int xIn, int yIn, int numParticles)
 Constructs a 2d SweepNPruneAlgorithmSimple. More...
 
 SweepNPruneAlgorithmSimple (int xIn, int yIn, int zIn, int numParticles)
 Constructs a 3d SweepNPruneAlgorithmSimple. More...
 
 SweepNPruneAlgorithmSimple (int xIn, int yIn, int zIn, double massIn, int numParticles)
 Constructs a 3d SweepNPruneAlgorithmSimple with orbital Physics. More...
 
- Public Member Functions inherited from Algorithm
 Algorithm (double xIn, double yIn)
 Constructs a 2 dimensional Algorithm. More...
 
 Algorithm (double xIn, double yIn, double zIn)
 Constructs a 3 dimensional Algorithm. More...
 
 Algorithm (double xIn, double yIn, double zIn, double centerMass)
 Constructs a 3 dimensional Algorithm with orbital Physics. More...
 
std::vector< Particle * > getParticles ()
 Returns the vector of Particles that the algorithm is tracking. More...
 
std::queue< Collision * > * getCollisions ()
 Returns the queue of Collisions that we haven't entered the warning window yet. More...
 
MultiQueuegetPositionQueue ()
 Returns the MultiQueue that contains upcoming Positions for each Particle. More...
 
std::mutex * getCollisionMutex ()
 Returns the Mutex locking the Collision queue. More...
 
ParticlegetCenterOfGravity ()
 Returns the massive Particle in the center responsible for Gravitation. More...
 
int getNumParts ()
 Returns the number of Particles the Algorithm is tracking. More...
 
int getTimestep ()
 Returns the timestep the Algorithm is currently calculating. More...
 
double getSystemKE ()
 Returns the system kinetic energy which is updated each timestep. More...
 
double getSystemPE ()
 Returns system potential energy which is updated each timestep. More...
 
PhysicsgetPhysics ()
 Returns the Physics object working for this Algorithm. More...
 
void setNumParts (int numParticles)
 Sets the number of Particles the Algorithm is tracking. More...
 
void createParticles2D (int numParticles)
 Sets the number of Particles, then generates that many to track. More...
 
void createParticles3D (int numParticles)
 Sets the number of Particles, then generates that many to track. More...
 
void createParticlesOrbit (int numParticles)
 Sets the number of Particles, then generates that many to track. More...
 
void respawnParticle (Particle *particle)
 
void enqueueCollisions (std::vector< Collision * > collisions)
 Pushes Collisions from the most recent timestep onto the queue of upcoming Collision$s. More...
 
void runOneTimestep ()
 Calculates the next timestep. More...
 
void run ()
 
void stop ()
 
void stepTime ()
 Calculates the next timestep and sets running to true. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Algorithm
ParticlegenerateParticleIn2D (int i)
 
ParticlegenerateParticleIn3D (int i)
 
ParticlegenerateParticleInOrbit (int i)
 
void regenerateParticleInOrbit (Particle *p)
 
bool checkForOverlap (Particle *p)
 
void enqueuePositions ()
 
void updateSystemKE ()
 
void updateSystemPE ()
 
void rescaleVelocities ()
 
void checkTimestep ()
 
- Protected Attributes inherited from Algorithm
std::vector< Particle * > particles
 
std::queue< Collision * > collisionQueue
 
std::mutex collisionMutex
 
MultiQueuepositionQueue
 
Physicsphysics
 
bool running
 
int numParts
 
int timestep
 
double xWinSize
 
double yWinSize
 
double zWinSize
 
double systemKE
 
double systemPE
 

Detailed Description

The SweepNPruneAlgorithmSimple class executes the sweep and prune method of collision detection.

This class stores the data necessary to track particle movements. At each timestep, it sorts the list of particles based on their minimum values in a particular dimension. Based on this sort it compares the Position of only Particles that overlap eachother in this dimension to see if they are farther appart than the sum of ther radii. if not, then a Collision has happened, and it gets resolved. Insertion sort is close to O(n) time on nearly sorted lists, and the list will always be nearly sorted because the particles move relatively slowly.

Constructor & Destructor Documentation

SweepNPruneAlgorithmSimple::SweepNPruneAlgorithmSimple ( int  xIn,
int  yIn,
int  numParticles 
)

Constructs a 2d SweepNPruneAlgorithmSimple.

This calls Algorithm::Algorithm() then creates the appropriate number of particles in 2-space. Then, for each particle, it will create a BoundingBox which will be maintained in a sorted list of BoundingBoxes.

Parameters
xInthe size of the x dimension of the space.
yInthe size of the y dimension of the space.
numParticlesthe number of Particles to spawn and track.
SweepNPruneAlgorithmSimple::SweepNPruneAlgorithmSimple ( int  xIn,
int  yIn,
int  zIn,
int  numParticles 
)

Constructs a 3d SweepNPruneAlgorithmSimple.

This calls Algorithm::Algorithm() then creates the appropriate number of particles in 3-space. Then, for each particle, it will create a BoundingBox which will be maintained in a sorted list of BoundingBoxes.

Parameters
xInthe size of the x dimension of the space.
yInthe size of the y dimension of the space.
zInthe size of the z dimension of the space.
numParticlesthe number of Particles to spawn and track.
SweepNPruneAlgorithmSimple::SweepNPruneAlgorithmSimple ( int  xIn,
int  yIn,
int  zIn,
double  massIn,
int  numParticles 
)

Constructs a 3d SweepNPruneAlgorithmSimple with orbital Physics.

This calls Algorithm::Algorithm() then creates the appropriate number of particles in 3-space with circular orbits. Then, for each particle, it will create a BoundingBox which will be maintained in a sorted list of BoundingBoxes.

Parameters
xInthe size of the x dimension of the space.
yInthe size of the y dimension of the space.
zInthe size of the z dimension of the space.
massInthe mass of the Particle responsible for gravity.
numParticlesthe number of Particles to spawn and track.

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