distance
fun distance(a: Particle, b: Particle, compliance: Float = 0.0f, rest: Float = Float.NaN): Link(source)
Keeps particles a and b apart, pushing and pulling, and returns its handle. Without a rest, it is as far apart as they are now. compliance is how far it gives per unit of force; 0 is rigid.
Throws
if a particle is gone, a is b, compliance is negative or not finite, or the rest length is not more than 0.
Samples
val world = PhysicsWorld()
val anchor = world.particles.add(x = 0f, y = 0f, mass = Particles.STATIC)
val bob = world.particles.add(x = 50f, y = 0f)
// A rigid stick: the bob swings on it like a pendulum, always 50 from the anchor.
val stick = world.constraints.distance(anchor, bob)
repeat(30) { world.step(1.seconds / 60) }
assertPrints(world.constraints.restLengthOf(stick), "50.0")
assertTrue(world.constraints.strainOf(stick) in -0.01f..0.01f)Content copied to clipboard