Strand

class Strand(source)

A rope or a chain made by PhysicsWorld.rope or PhysicsWorld.chain: its particles in order from one end to the other, the links between neighbours, and the bends at every particle but the ends (empty when it has none). They are ordinary world particles and constraints; this just remembers which ones.

toString gives how many of each it has, for example Strand(particles=11, links=10, bends=9).

Samples

val world = PhysicsWorld()
val rope = world.rope(fromX = 0f, fromY = 0f, toX = 100f, toY = 0f, segments = 10)
assertPrints(rope, "Strand(particles=11, links=10, bends=0)")
// Its start is pinned where it was made; the rest falls and hangs.
assertPrints(world.particles.inverseMassOf(rope.first), "0.0")
assertPrints(rope.restLength(world), "100.0")

Properties

Link copied to clipboard

The bends: the one at particles[i + 1] is bends[i].

Link copied to clipboard

The particle at the start.

Link copied to clipboard

The particle at the end.

Link copied to clipboard

The links between neighbours: the one from particles[i] to particles[i + 1] is links[i].

Link copied to clipboard

The particles, from the start to the end.

Functions

Link copied to clipboard

Returns how long this strand is now in world, along its particles.

Link copied to clipboard

Returns how long this strand is at rest in world: the sum of its links' rest lengths.

Link copied to clipboard
open override fun toString(): String