Particle

Particle is the main object of this physics engine. It is a 2D circle that is treated like a point mass at the center and does not rotate. Particle is also a HashGridItem so it can be added to a SpatialHashGrid.

Constructor

new Particle(pos, vel, mass, radius, bounciness, charge, color)

Instantiates new Particle

Parameters:
NameTypeDefaultDescription
posVector2D

cartesian coordinates of the particle

velVector2D

velocity of the particle

massNumber
radiusNumber
bouncinessNumber1

a value in [0,1] that represents the amount of energy retained after collision

chargeNumber0

similar to real physical charge

colorStringblack

currently only supports HTML canvas colors format

Extends

Methods

addNearBehavior(b) → {Boolean}

Adds a NearBehavior to the particle if not added already

Parameters:
NameTypeDescription
bNearBehavior
Returns:

true if successfully added

Type: 
Boolean

addSelfBehavior(b) → {Boolean}

Adds a SelfBehavior to the particle if not added already

Parameters:
NameTypeDescription
bSelfBehavior
Returns:

true if successfully added

Type: 
Boolean

applyAcceleration(a, timeStep)

Increments the velocity by an acceleration a

Parameters:
NameTypeDescription
aVector2D
timeStepNumber

applyForce(f, timeStep)

Applies force f to the velocity

Parameters:
NameTypeDescription
fVector2D
timeStepNumber

applyVelocity(v, timeStep)

Increments the position by velocity v

Parameters:
NameTypeDescription
vVector2D
timeStepNumber

clearBehaviors()

Clears all behaviors of the particle

getHashDimensions() → {Array.<Number>}

Computes the dimensions of the item for the HashGrid.

Returns:
Type: 
Array.<Number>

getHashPos() → {Array.<Number>}

Computes the coordinate position for the item within the HashGrid, expects center position.

Returns:
Type: 
Array.<Number>

removeNearBehavior(b) → {Boolean}

Removes NearBehavior b if the particle has b

Parameters:
NameTypeDescription
bNearBehavior
Returns:

true if the action is successful

Type: 
Boolean

removeSelfBehavior(b) → {Boolean}

Removes SelfBehavior b if the particle has b

Parameters:
NameTypeDescription
bSelfBehavior
Returns:

true if the action is successful

Type: 
Boolean