Class pv.Force.charge
An n-body force, as defined by Coulomb's law or Newton's law of gravitation, inversely proportional to the square of the distance between particles. Note that the force is independent of the mass of the associated particles, and that the particles do not have charges of varying magnitude; instead, the attraction or repulsion of all particles is globally specified as the charge #constant.
This particular implementation uses the Barnes-Hut algorithm. For details,
see "A
hierarchical O(N log N) force-calculation algorithm", J. Barnes &
P. Hut, Nature 1986.
Defined in: ChargeForce.js.
Constructor Attributes | Constructor Name and Description |
---|---|
Constructs a new charge force, with an optional charge constant.
|
Method Attributes | Method Name and Description |
---|---|
apply(particles, q)
Applies this force to the specified particles.
|
|
constant(x)
Sets or gets the charge constant.
|
|
domain(a, b)
Sets or gets the domain; specifies the minimum and maximum domain within
which charge forces are applied.
|
|
theta(x)
Sets or gets the Barnes-Hut approximation factor.
|
Class Detail
pv.Force.charge(k)
Constructs a new charge force, with an optional charge constant. The charge
constant can be negative for repulsion (e.g., particles with electrical
charge of equal sign), or positive for attraction (e.g., massive particles
with mutual gravity). The default charge constant is -40.
- Parameters:
- {number} k Optional
- the charge constant.
Method Detail
apply(particles, q)
Applies this force to the specified particles. The force is applied between
all pairs of particles within the domain, using the specified quadtree to
accelerate n-body force calculation using the Barnes-Hut approximation
criterion.
- Parameters:
- {pv.Particle} particles
- particles to which to apply this force.
- {pv.Quadtree} q
- a quadtree for spatial acceleration.
{pv.Force.charge}
constant(x)
Sets or gets the charge constant. If an argument is specified, it is the
new charge constant. The charge constant can be negative for repulsion
(e.g., particles with electrical charge of equal sign), or positive for
attraction (e.g., massive particles with mutual gravity). The default
charge constant is -40.
- Parameters:
- {number} x
- the charge constant.
- Returns:
- {pv.Force.charge} this.
{pv.Force.charge}
domain(a, b)
Sets or gets the domain; specifies the minimum and maximum domain within
which charge forces are applied. A minimum distance threshold avoids
applying forces that are two strong (due to granularity of the simulation's
numeric integration). A maximum distance threshold improves performance by
skipping force calculations for particles that are far apart.
The default domain is [2, 500].
- Parameters:
- {number} a
- {number} b
- Returns:
- {pv.Force.charge} this.
{pv.Force.charge}
theta(x)
Sets or gets the Barnes-Hut approximation factor. The Barnes-Hut
approximation criterion is the ratio of the size of the quadtree node to
the distance from the point to the node's center of mass is beneath some
threshold.
- Parameters:
- {number} x
- the new Barnes-Hut approximation factor.
- Returns:
- {pv.Force.charge} this.