Packageflare.physics
Classpublic class NBodyForce
ImplementsIForce

Force simulating an N-Body force of charged particles with pairwise interaction, such as gravity or electrical charge. This class uses a quad-tree structure to aggregate charge values and optimize computation. The force function is a standard inverse-square law (though in this case approximated due to optimization): F = G m1 m2 / d^2, where G is a constant (e.g., gravitational constant), m1 and m2 are the masses (charge) of the particles, and d is the distance between them.

The algorithm used is that of J. Barnes and P. Hut, in their research paper A Hierarchical O(n log n) force calculation algorithm, Nature, v.324, December 1986. For more details on the algorithm, see one of the following links:



Public Properties
 PropertyDefined by
  gravitation : Number
The gravitational constant to use.
NBodyForce
  maxDistance : Number
The maximum distance over which forces are exerted.
NBodyForce
  minDistance : Number
The minumum effective distance over which forces are exerted.
NBodyForce
Public Methods
 MethodDefined by
  
NBodyForce(g:Number = -1, max:Number = 200, min:Number = 2, eps:Number = 0.01, t:Number = 0.9)
Creates a new NBodyForce with given parameters.
NBodyForce
  
apply(sim:Simulation):void
Applies this force to a simulation.
NBodyForce
Property detail
gravitationproperty
gravitation:Number  [read-write]

The gravitational constant to use. Negative values produce a repulsive force.

Implementation
    public function get gravitation():Number
    public function set gravitation(value:Number):void
maxDistanceproperty 
maxDistance:Number  [read-write]

The maximum distance over which forces are exerted. Any greater distances will be ignored.

Implementation
    public function get maxDistance():Number
    public function set maxDistance(value:Number):void
minDistanceproperty 
minDistance:Number  [read-write]

The minumum effective distance over which forces are exerted. Any lesser distances will be treated as the minimum.

Implementation
    public function get minDistance():Number
    public function set minDistance(value:Number):void
Constructor detail
NBodyForce()constructor
public function NBodyForce(g:Number = -1, max:Number = 200, min:Number = 2, eps:Number = 0.01, t:Number = 0.9)

Creates a new NBodyForce with given parameters.

Parameters
g:Number (default = -1) — the gravitational constant to use. Negative values produce a repulsive force.
 
max:Number (default = 200) — a maximum distance over which the force should operate. Particles separated by more than this distance will not interact.
 
min:Number (default = 2) — the minimum distance over which the force should operate. Particles closer than this distance will interact as if they were the minimum distance apart. This helps avoid extreme forces. Helpful when particles are very close together.
 
eps:Number (default = 0.01) — an epsilon values for determining a minimum distance between particles
 
t:Number (default = 0.9) — the theta parameter for the Barnes-Hut approximation. Determines the level of approximation (default value if 0.9).
Method detail
apply()method
public function apply(sim:Simulation):void

Applies this force to a simulation.

Parameters
sim:Simulation — the Simulation to apply the force to