Click or drag to resize
Particle Class
The Particle class represents a particle moving in the unit box, with a given position, velocity, Radius, and Mass. Methods are provided for moving the particle and for predicting and resolvling elastic collisions with vertical walls, horizontal walls, and other particles. This data type is mutable because the position and velocity change.
Inheritance Hierarchy

Namespace: Algs4Net
Assembly: Algs4Net (in Algs4Net.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
C#
public class Particle : BasicVisual

The Particle type exposes the following members.

Constructors
  NameDescription
Public methodParticle
Default constructor to be used with member initializers to set member values
Public methodParticle(DrawingWindow)
Initializes a particle with a random position and velocity. The position is uniform in the unit box; the velocity in either direciton is chosen uniformly at random. Member initializers will replace these random values.
Top
Properties
  NameDescription
Public propertyCollisionCount
Returns the number of collisions involving this particle with vertical walls, horizontal walls, or other particles. This is equal to the number of calls to BounceOff(Particle), BounceOffVerticalWall, and BounceOffHorizontalWall
Public propertyMass
The particle's mass
Public propertyRadius
The particle's radius
Public propertyVx
Velocity along x-coordinate
Public propertyVy
Velocity along y-coordinate
Public propertyX
The X coordinate from the left
Public propertyY
The Y coordinate from the top
Top
Methods
  NameDescription
Public methodBounceOff
Updates the velocities of this particle and the specified particle according to the laws of elastic collision. Assumes that the particles are colliding at this instant.
Public methodBounceOffHorizontalWall
Updates the velocity of this particle upon collision with a horizontal wall (by reflecting the velocity in the Y-direction). Assumes that the particle is colliding with a horizontal wall at this instant.
Public methodBounceOffVerticalWall
Updates the velocity of this particle upon collision with a vertical wall (by reflecting the velocity in the X-direction). Assumes that the particle is colliding with a vertical wall at this instant.
Public methodDraw
Draws the particle as a filled circle
(Overrides BasicVisualDraw.)
Public methodKineticEnergy
Returns the kinetic energy of this particle. The kinetic energy is given by the formula 1/2 MV2, where M is the Mass of this particle and V is its velocity.
Public methodMove
Moves this particle in a straight line (based on its velocity) for the specified amount of time.
Public methodTimeToHit
Returns the amount of time for this particle to collide with the specified particle, assuming no interening collisions.
Public methodTimeToHitHorizontalWall
Returns the amount of time for this particle to collide with a horizontal wall, assuming no interening collisions.
Public methodTimeToHitVerticalWall
Returns the amount of time for this particle to collide with a vertical wall, assuming no interening collisions.
Public methodToString
Returns useful particle info for debugging
(Overrides ObjectToString.)
Top
Remarks

For additional documentation, see Section 6.1 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.

This class is a C# port from the original Java class Particle implementation by the respective authors.

See Also