Particle Class |
Namespace: Algs4Net
public class Particle : BasicVisual
The Particle type exposes the following members.
Name | Description | |
---|---|---|
![]() | Particle |
Default constructor to be used with member initializers to set member
values
|
![]() | Particle(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. |
Name | Description | |
---|---|---|
![]() | CollisionCount |
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 |
![]() | Mass |
The particle's mass
|
![]() | Radius |
The particle's radius
|
![]() | Vx |
Velocity along x-coordinate
|
![]() | Vy |
Velocity along y-coordinate
|
![]() | X |
The X coordinate from the left
|
![]() | Y |
The Y coordinate from the top
|
Name | Description | |
---|---|---|
![]() | BounceOff |
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. |
![]() | BounceOffHorizontalWall |
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. |
![]() | BounceOffVerticalWall |
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. |
![]() | Draw |
Draws the particle as a filled circle
(Overrides BasicVisualDraw.) |
![]() | KineticEnergy |
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. |
![]() | Move |
Moves this particle in a straight line (based on its velocity)
for the specified amount of time. |
![]() | TimeToHit |
Returns the amount of time for this particle to collide with the specified
particle, assuming no interening collisions. |
![]() | TimeToHitHorizontalWall |
Returns the amount of time for this particle to collide with a horizontal
wall, assuming no interening collisions. |
![]() | TimeToHitVerticalWall |
Returns the amount of time for this particle to collide with a vertical
wall, assuming no interening collisions. |
![]() | ToString |
Returns useful particle info for debugging
(Overrides ObjectToString.) |
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.