public class NBodyForce extends AbstractForce
Force function which computes an n-body force such as gravity, anti-gravity, or the results of electric charges. This function implements the the Barnes-Hut algorithm for efficient n-body force simulations, using a quad-tree with aggregated mass values to compute the n-body force in O(N log N) time, where N is the number of ForceItems.
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 --
Modifier and Type | Class and Description |
---|---|
static class |
NBodyForce.QuadTreeNode
Represents a node in the quadtree.
|
static class |
NBodyForce.QuadTreeNodeFactory
Helper class to minimize number of object creations across multiple
uses of the quadtree.
|
Modifier and Type | Field and Description |
---|---|
static int |
BARNES_HUT_THETA |
static float |
DEFAULT_DISTANCE |
static float |
DEFAULT_GRAV_CONSTANT |
static float |
DEFAULT_MAX_DISTANCE |
static float |
DEFAULT_MAX_GRAV_CONSTANT |
static float |
DEFAULT_MAX_THETA |
static float |
DEFAULT_MIN_DISTANCE |
static float |
DEFAULT_MIN_GRAV_CONSTANT |
static float |
DEFAULT_MIN_THETA |
static float |
DEFAULT_THETA |
static int |
GRAVITATIONAL_CONST |
static int |
MIN_DISTANCE |
maxValues, minValues, params
Constructor and Description |
---|
NBodyForce()
Create a new NBodyForce with default parameters.
|
NBodyForce(float gravConstant,
float minDistance,
float theta)
Create a new NBodyForce.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clears the quadtree of all entries.
|
void |
getForce(ForceItem item)
Calculates the force vector acting on the given item.
|
protected java.lang.String[] |
getParameterNames() |
void |
init(ForceSimulator fsim)
Initialize the simulation with the provided enclosing simulation.
|
void |
insert(ForceItem item)
Inserts an item into the quadtree.
|
boolean |
isItemForce()
Returns true.
|
getForce, getMaxValue, getMinValue, getParameter, getParameterCount, getParameterName, isSpringForce, setMaxValue, setMinValue, setParameter
public static final float DEFAULT_GRAV_CONSTANT
public static final float DEFAULT_MIN_GRAV_CONSTANT
public static final float DEFAULT_MAX_GRAV_CONSTANT
public static final float DEFAULT_DISTANCE
public static final float DEFAULT_MIN_DISTANCE
public static final float DEFAULT_MAX_DISTANCE
public static final float DEFAULT_THETA
public static final float DEFAULT_MIN_THETA
public static final float DEFAULT_MAX_THETA
public static final int GRAVITATIONAL_CONST
public static final int MIN_DISTANCE
public static final int BARNES_HUT_THETA
public NBodyForce()
public NBodyForce(float gravConstant, float minDistance, float theta)
gravConstant
- the gravitational constant to use. Nodes will
attract each other if this value is positive, and will repel each
other if it is negative.minDistance
- the distance within which two particles will
interact. If -1, the value is treated as infinite.theta
- the Barnes-Hut parameter theta, which controls when
an aggregated mass is used rather than drilling down to individual
item mass values.public boolean isItemForce()
isItemForce
in interface Force
isItemForce
in class AbstractForce
Force.isItemForce()
protected java.lang.String[] getParameterNames()
getParameterNames
in class AbstractForce
AbstractForce.getParameterNames()
public void clear()
public void init(ForceSimulator fsim)
init
in interface Force
init
in class AbstractForce
fsim
- the enclosing ForceSimulatorpublic void insert(ForceItem item)
item
- the ForceItem to add.java.lang.IllegalStateException
- if the current location of the item is
outside the bounds of the quadtreepublic void getForce(ForceItem item)
getForce
in interface Force
getForce
in class AbstractForce
item
- the ForceItem for which to compute the forceForce.getForce(prefuse.util.force.ForceItem)
Copyright ? 2013 Regents of the University of California