area

fun area(ring: List<Particle>, compliance: Float = 0.0f, rest: Float = Float.NaN): Area(source)

Keeps the area inside the closed ring of particles ring, in order, at rest, and returns its handle. Without a rest, it is the area the ring has now. The list is copied.

Throws

if ring has fewer than 3 particles, one of them is gone, or compliance is negative or not finite.

Samples

val world = PhysicsWorld()
val ring = listOf(
    world.particles.add(x = 0f, y = 0f),
    world.particles.add(x = 20f, y = 0f),
    world.particles.add(x = 20f, y = 20f),
    world.particles.add(x = 0f, y = 20f),
)
// Keeps the four covering 400 units squared, however they are pushed about.
val area = world.constraints.area(ring)
assertPrints(world.constraints.restAreaOf(area), "400.0")