ballwar.model
Class AElasticMassCollisionCmd
java.lang.Object
ballwar.model.AElasticMassCollisionCmd
- All Implemented Interfaces:
- IBallCmd
public abstract class AElasticMassCollisionCmd
- extends Object
- implements IBallCmd
Superclass for commands involving elastic collisions of round balls with individual masses.
This superclass provides protected utility methods for the calculations.
Sub-classes must implement the "public void apply(Ball target)" method of IBallCmd.
The apply method must determine if the source and target balls are within collision distance
and then calculate the impulse of the collision. The collisionUpdate method can be used to
change the velocity of the source and target balls by calling it with appropriate source and target
balls and with the appropriate sign on the impulse.
Copyright (c) 2010 by Stephen Wong
- Author:
- Stephen Wong
Field Summary |
private double |
Nudge
The amount to add to the separation distance to insure that the two balls are beyond collision distance |
Method Summary |
protected Point2D.Double |
impulse(Point lSource,
Point vSource,
Point lTarget,
Point vTarget,
double reducedMass,
double distance,
double deltaR)
Calculates the impulse (change in momentum) of the collision in the direction from the source to the target
This method calculates the impulse on the source ball. |
protected double |
reducedMass(double mSource,
double mTarget)
Returns the reduced mass of the two balls (m1*m2)/(m1+m2)
Gives correct result if one of the balls has infinite mass. |
protected void |
updateCollision(Ball source,
Ball target,
double impX,
double impY)
Updates the velocity of the source ball, given an impulse, then calls the source's update strategy's
updateCollision method. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Nudge
private double Nudge
- The amount to add to the separation distance to insure that the two balls are beyond collision distance
AElasticMassCollisionCmd
public AElasticMassCollisionCmd()
reducedMass
protected double reducedMass(double mSource,
double mTarget)
- Returns the reduced mass of the two balls (m1*m2)/(m1+m2)
Gives correct result if one of the balls has infinite mass.
- Parameters:
mSource
- Mass of the source ballmTarget
- Mass of the target ball
impulse
protected Point2D.Double impulse(Point lSource,
Point vSource,
Point lTarget,
Point vTarget,
double reducedMass,
double distance,
double deltaR)
- Calculates the impulse (change in momentum) of the collision in the direction from the source to the target
This method calculates the impulse on the source ball. The impulse on the target ball is the negative of the result.
Also moves source ball out of collision range along normal direction.
The change in velocity of the source ball is the impulse divided by the source's mass
The change in velocity of the target ball is the negative of the impulse divided by the target's mass
Operational note: Even though theoretically, the difference in velocities of two balls should be co-linear
with the normal line between them, the discrete nature of animations means that the point where collision is
detected may not be at the same point as the theoretical contact point. This method calculates the
rebound directions as if the two balls were the appropriate radii such that they had just contacted
_at_the_point_of_collision_detection_. This may give slightly different rebound direction than one
would calculate if they contacted at the theoretical point given by their actual radii.
- Parameters:
lSource
- Location of the source ballvSource
- Velocity of the source balllTarget
- Location of the target ballvTarget
- Velocity of the target ballreducedMass
- Reduced mass of the two ballsdistance
- Distance between the two balls.deltaR
- The difference in minimum minus actual separation. Should be a pos. value.
- Returns:
updateCollision
protected void updateCollision(Ball source,
Ball target,
double impX,
double impY)
- Updates the velocity of the source ball, given an impulse, then calls the source's update strategy's
updateCollision method.
The change in velocity is the impulse divided by the (source) ball's mass.
To change the velocity of the target ball, switch the source and target input parameters and negate the impulse values.
- Parameters:
source
- The ball to updatetarget
- The ball being collided withimpX
- x-coordinate of the impulseimpY
- y-coordinate of the impulse