peer Repulsion3D
fun <A : AgentLike> peerRepulsion3D(radius: Double, minDistance: Double = 0.0, falloff: (distance: Double) -> Double): Force3D<A>(source)
3D peer-peer repulsion. For each neighbor inside radius (excluding self), apply a force along the direction away from the neighbor with magnitude given by falloff of the inter- agent distance. Distances are clamped at minDistance to keep falloff finite at contact. Uses ContinuousVolume.delta for the inter-agent direction so torus-wrapped 3D worlds compute the correct shortest-way vector.
Use for any 3D peer repulsion shape — Reynolds boids (1.0 / d), Helbing-style social-force (A * exp((r - d) / B)), drone collision-avoidance with custom falloff.
// Boids in 3D — inverse distance.
dynamics.addForce(peerRepulsion3D(radius = 3.0) { d -> 1.0 / d })
// Drone TCAS-style avoidance — exponential.
dynamics.addForce(peerRepulsion3D(radius = 8.0, minDistance = 0.1) { d ->
500.0 * exp((2.0 - d) / 0.5)
})Content copied to clipboard