Class pv.Simulation
Represents a particle simulation. Particles are massive points in two-dimensional space. Forces can be applied to these particles, causing them to move. Constraints can also be applied to restrict particle movement, for example, constraining particles to a fixed position, or simulating collision between circular particles with area.
The simulation uses Position Verlet integration, due to the ease with which geometric constraints can be implemented. For each time step, Verlet integration is performed, new forces are accumulated, and then constraints are applied.
The simulation makes two simplifying assumptions: all particles are equal-mass, and the time step of the simulation is fixed. It would be easy to incorporate variable-mass particles as a future enhancement. Variable time steps are also possible, but are likely to introduce instability in the simulation.
This class can be used directly to simulate particle interaction.
Alternatively, for network diagrams, see pv.Layout.Force.
Defined in: Simulation.js.
Constructor Attributes | Constructor Name and Description |
---|---|
pv.Simulation(particles)
Constructs a new simulation for the specified particles.
|
Field Attributes | Field Name and Description |
---|---|
The constraints in the simulation.
|
|
The forces in the simulation.
|
|
The particles in the simulation.
|
Method Attributes | Method Name and Description |
---|---|
constraint(c)
Adds the specified constraint to the simulation.
|
|
force(f)
Adds the specified force to the simulation.
|
|
particle(p)
Adds the specified particle to the simulation.
|
|
stabilize(n)
Apply constraints, and then set the velocities to zero.
|
|
step()
Advances the simulation one time-step.
|
- Parameters:
- {array} particles
- an array of pv.Particles to simulate.
- Parameters:
- {pv.Constraint} c
- the new constraint.
- Returns:
- {pv.Simulation} this.
- Parameters:
- {pv.Force} f
- the new force.
- Returns:
- {pv.Simulation} this.
- Parameters:
- {pv.Particle} p
- the new particle.
- Returns:
- {pv.Simulation} this.
- Parameters:
- n
- Returns:
- {pv.Simulation} this.