toxi.physics2d
Class VerletParticle2D

java.lang.Object
  extended by toxi.geom.Vec2D
      extended by toxi.physics2d.VerletParticle2D
All Implemented Interfaces:
java.lang.Comparable<toxi.geom.Vec2D>

public class VerletParticle2D
extends toxi.geom.Vec2D

An individual 3D particle for use by the VerletPhysics and VerletSpring classes. A particle has weight, can be locked in space and its position constrained inside an (optional) axis-aligned bounding box.

Author:
toxi

Nested Class Summary
 
Nested classes/interfaces inherited from class toxi.geom.Vec2D
toxi.geom.Vec2D.Axis
 
Field Summary
 toxi.geom.Rect bounds
          Bounding box, by default set to null to disable
 java.util.ArrayList<Particle2DConstraint> constraints
          An optional particle constraints, called immediately after a particle is updated (and only used if particle is unlocked (default)
 
Fields inherited from class toxi.geom.Vec2D
MAX_VALUE, MIN_VALUE, x, X_AXIS, y, Y_AXIS, ZERO
 
Constructor Summary
VerletParticle2D(float x, float y)
          Creates particle at position xyz
VerletParticle2D(float x, float y, float w)
          Creates particle at position xyz with weight w
VerletParticle2D(toxi.geom.Vec2D v)
          Creates particle at the position of the passed in vector
VerletParticle2D(toxi.geom.Vec2D v, float w)
          Creates particle with weight w at the position of the passed in vector
VerletParticle2D(VerletParticle2D p)
          Creates a copy of the passed in particle
 
Method Summary
 VerletParticle2D addConstraint(Particle2DConstraint c)
          Adds the given constraint implementation to the list of constraints applied to this particle at each time step.
 VerletParticle2D addVelocity(toxi.geom.Vec2D v)
           
 void applyConstraints()
           
 VerletParticle2D clearVelocity()
           
 toxi.geom.Vec2D getPreviousPosition()
          Returns the particle's position at the most recent time step.
 float getWeight()
           
 boolean isLocked()
           
 VerletParticle2D lock()
          Locks/immobilizes particle in space
 VerletParticle2D removeAllConstraints()
          Removes any currently applied constraints from this particle.
 boolean removeConstraint(Particle2DConstraint c)
          Attempts to remove the given constraint instance from the list of active constraints.
 VerletParticle2D scaleVelocity(float scl)
           
 void setWeight(float w)
           
 VerletParticle2D unlock()
          Unlocks particle again
 
Methods inherited from class toxi.geom.Vec2D
abs, add, add, addSelf, addSelf, angleBetween, angleBetween, clear, closestPointOnLine, closestPointOnTriangle, compareTo, constrain, constrain, copy, cross, distanceTo, distanceToSquared, dot, equals, equalsWithTolerance, floor, frac, fromTheta, getAbs, getComponent, getConstrained, getFloored, getFrac, getInverted, getLimited, getNormalized, getNormalizedTo, getPerpendicular, getReciprocal, getRotated, getSignum, hashCode, heading, interpolateTo, interpolateTo, interpolateToSelf, interpolateToSelf, intersectRayCircle, invert, isInCircle, isInRectangle, isInTriangle, isZeroVector, jitter, jitter, jitter, limit, magnitude, magSquared, max, max, maxSelf, min, min, minSelf, normalize, normalizeTo, perpendicular, pointInPolygon, randomVector, randomVector, reciprocal, rotate, scale, scale, scale, scaleSelf, scaleSelf, scaleSelf, set, set, setComponent, signum, sub, sub, subSelf, subSelf, tangentNormalOfEllipse, to3DXY, to3DXZ, to3DYZ, toArray, toCartesian, toPolar, toString
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

bounds

public toxi.geom.Rect bounds
Bounding box, by default set to null to disable


constraints

public java.util.ArrayList<Particle2DConstraint> constraints
An optional particle constraints, called immediately after a particle is updated (and only used if particle is unlocked (default)

Constructor Detail

VerletParticle2D

public VerletParticle2D(float x,
                        float y)
Creates particle at position xyz

Parameters:
x -
y -

VerletParticle2D

public VerletParticle2D(float x,
                        float y,
                        float w)
Creates particle at position xyz with weight w

Parameters:
x -
y -
w -

VerletParticle2D

public VerletParticle2D(toxi.geom.Vec2D v)
Creates particle at the position of the passed in vector

Parameters:
v - position

VerletParticle2D

public VerletParticle2D(toxi.geom.Vec2D v,
                        float w)
Creates particle with weight w at the position of the passed in vector

Parameters:
v - position
w - weight

VerletParticle2D

public VerletParticle2D(VerletParticle2D p)
Creates a copy of the passed in particle

Parameters:
p -
Method Detail

addConstraint

public VerletParticle2D addConstraint(Particle2DConstraint c)
Adds the given constraint implementation to the list of constraints applied to this particle at each time step.

Parameters:
c - constraint instance
Returns:
itself

addVelocity

public VerletParticle2D addVelocity(toxi.geom.Vec2D v)

applyConstraints

public void applyConstraints()

clearVelocity

public VerletParticle2D clearVelocity()

getPreviousPosition

public toxi.geom.Vec2D getPreviousPosition()
Returns the particle's position at the most recent time step.

Returns:
previous position

getWeight

public float getWeight()
Returns:
the weight

isLocked

public boolean isLocked()
Returns:
true, if particle is locked

lock

public VerletParticle2D lock()
Locks/immobilizes particle in space

Returns:
itself

removeAllConstraints

public VerletParticle2D removeAllConstraints()
Removes any currently applied constraints from this particle.

Returns:
itself

removeConstraint

public boolean removeConstraint(Particle2DConstraint c)
Attempts to remove the given constraint instance from the list of active constraints.

Parameters:
c - constraint to remove
Returns:
true, if successfully removed

scaleVelocity

public VerletParticle2D scaleVelocity(float scl)

setWeight

public void setWeight(float w)

unlock

public VerletParticle2D unlock()
Unlocks particle again

Returns:
itself