impose {particles} | R Documentation |
Assign a force or constraint to a simulation
Description
This function adds a new force/constraint to the simulation and trains the it
on the current particle graph. The parameters passed on to the training are
using tidy evaluation from the rlang package. Depending on the
force/constraint the data getting referenced is either the node or the edge
data of the particle graph. Both forces and constraints manipulate position
and velocity of the particles but they differ in when the are applied during
a generation. First forces are applied sequentially and the resulting
velocity is added to the resulting position after velocity_decay
has been
applied. After this operation any constraint is imposed on the results. In
general, forces tends to calculate velocity adjustments, while constraints
modify position and velocity directly, but this difference is not in any way
enforced.
Usage
impose(simulation, constraint, ..., name, include = TRUE)
reimpose(simulation, name, ...)
unimpose(simulation, name)
wield(simulation, force, ..., name, include = TRUE)
rewield(simulation, name, ...)
unwield(simulation, name)
Arguments
simulation |
A simulation object |
constraint |
A constraint object |
... |
Parameters passed on to the training of the force or constraint |
name |
The name of the force. For use when accessing the force at a later stage. If no name is given the force is accessible by its index in the stack. |
include |
The particles to be affected by this force. Defaults to every particle in the simulation (tidy eval) |
force |
A force object |
Details
wield()
and impose()
adds forces and constraints to the simulation
respectively. unwield()
and unimpose()
removes forces and constraints
based on name or index. rewield()
and reimpose()
modifies existing forces
and constraints based on name or index and retrains them.
Value
A simulation with the force or constraint added
Examples
graph <- tidygraph::create_notable('folkman')
graph |>
simulate() |>
wield(link_force)