Class pv.Constraint.position
Constraints particles to a fixed position. The fixed position per particle is determined using a given position function, which defaults to function(d) d.fix.
If the position function returns null, then no position constraint is applied to the given particle. Otherwise, the particle's position is set to the returned position, as expressed by a pv.Vector. (Note: the position does not need to be an instance of pv.Vector, but simply an object with x and y attributes.)
This constraint also supports a configurable alpha parameter, which
defaults to 1. If the alpha parameter is in the range [0,1], then rather than
setting the particle's new position directly to the position returned by the
supplied position function, the particle's position is interpolated towards
the fixed position. This results is a smooth (exponential) drift towards the
fixed position, which can increase the stability of the physics simulation.
In addition, the alpha parameter can be decayed over time, relaxing the
position constraint, which helps to stabilize on an optimal solution.
Defined in: PositionConstraint.js.
Constructor Attributes | Constructor Name and Description |
---|---|
Constructs a default position constraint using the fix attribute.
|
Method Attributes | Method Name and Description |
---|---|
alpha(x)
Sets or gets the alpha parameter for position interpolation.
|
|
apply(particles)
Applies this constraint to the specified particles.
|
- Parameters:
- {function} f Optional
- the position function.
- Parameters:
- {number} x
- the new alpha parameter, in the range [0,1].
- Returns:
- {pv.Constraint.position} this.
- Parameters:
- {pv.Particle} particles
- particles to which to apply this constraint.