Class pv.Force.spring
Extends
pv.Force.
Implements a spring force, per Hooke's law. The spring force can be
configured with a tension constant, rest length, and damping factor. The
tension and damping will automatically be normalized using the inverse square
root of the maximum link degree of attached nodes; this makes springs weaker
between nodes of high link degree.
Unlike other forces (such as charge and drag forces) which may be applied
globally, spring forces are only applied between linked particles. Therefore,
an array of links must be specified before this force can be applied; the
links should be an array of pv.Layout.Network.Links. See also
pv.Layout.Force for an example of using spring and charge forces for
network layout.
Defined in: SpringForce.js.
Constructor Attributes | Constructor Name and Description |
---|---|
Constructs a new spring force with the specified constant.
|
Method Attributes | Method Name and Description |
---|---|
apply(particles)
Applies this force to the specified particles.
|
|
constant(x)
Sets or gets the spring constant.
|
|
damping(x)
The spring damping factor, in the range [0,1].
|
|
length(x)
The spring rest length.
|
|
links(x)
Sets or gets the links associated with this spring force.
|
- Parameters:
- {number} k
- the spring constant.
- Parameters:
- {pv.Particle} particles
- particles to which to apply this force.
- Parameters:
- {number} x
- the new spring constant.
- Returns:
- {pv.Force.spring} this, or the current spring constant.
- Parameters:
- {number} x
- the new spring damping factor.
- Returns:
- {pv.Force.spring} this, or the current spring damping factor.
- Parameters:
- {number} x
- the new spring rest length.
- Returns:
- {pv.Force.spring} this, or the current spring rest length.
- Parameters:
- {array} x
- the new array of links.
- Returns:
- {pv.Force.spring} this, or the current array of links.