Package-level declarations

Types

Link copied to clipboard
class Body(val nodes: List<Node>, val boundaryNodes: List<Int> = emptyList(), val links: List<Link> = emptyList(), val boundaryLinks: List<Int> = emptyList(), val triangles: List<Triangle> = emptyList(), var inverseBodyMass: Double = 1.0, var static: Boolean = false)

Represents a physical body in a simulation composed of nodes, links, and triangles.

Link copied to clipboard
class BodyAreaConstraint(val body: Body, var compliance: Double = 0.0, var iterations: Int = 1) : Constraint

Represents a constraint that maintains a specified area for a deformable body.

Link copied to clipboard

BoundaryNodeRelaxForce is a type of force that acts on the boundary nodes of a Body. It aims to relax the boundary nodes by adjusting their velocities based on neighboring node positions. Each boundary node is influenced by the midpoint of its neighboring boundary nodes, providing a smoothing effect.

Link copied to clipboard

Interface for detecting broad-phase collisions in a physics simulation.

Link copied to clipboard

An interface representing a constraint that resolves collisions between two bodies in a simulation.

Link copied to clipboard
interface Constraint

Represents a constraint in a physical system, which influences the behavior of a Body.

Link copied to clipboard
interface Force

Represents a physical force that can be applied to a Body in a simulation.

Link copied to clipboard
class ForceSimulation(val bodies: MutableList<Body> = mutableListOf())

Represents a physics simulation of interacting bodies.

Link copied to clipboard

Represents a constant gravitational force applied to a physical body in a simulation.

Link copied to clipboard
interface InterbodyForce

Interface representing a force interaction between two physical bodies in a simulation.

Link copied to clipboard
class Link(var source: Int, var target: Int)

Represents a connection or relationship between two Nodes, identified by their indices.

Link copied to clipboard
class LinkLengthConstraint(val body: Body, var compliance: Double = 0.0, var iterations: Int = 1) : Constraint

A constraint that enforces the lengths of links between nodes within a Body.

Link copied to clipboard
class ManyNodeForce(val body: Body) : Force
Link copied to clipboard

A naive implementation of a broad-phase collision detection algorithm.

Link copied to clipboard
class Node(var position: Vector2, var prevPosition: Vector2, var velocity: Vector2, var inverseMass: Double = 1.0, var radius: Double = 0.0, var id: Int = 0)

Represents a single physical node with position, velocity, and related properties.

Link copied to clipboard

Represents a circular constraint applied to nodes of a physical body.

Link copied to clipboard

Represents a constraint for resolving collisions between nodes within a physical body.

Link copied to clipboard

Represents a constraint that enforces nodes within a body to remain near the defined contour of a rectangle.

Link copied to clipboard
class NodeRepulseForce(val body: Body) : Force

Represents a repulsive force applied to nodes within a specified search radius.

Link copied to clipboard
class NodeRepulseForceBVH(val body: Body) : Force

Represents a repulsive force applied on nodes of a Body using a bounding volume hierarchy (BVH) for optimization.

Link copied to clipboard

Implementation of the InterbodyForce interface that applies a repulsive force between the nodes of two physical bodies based on their proximity, utilizing a bounding volume hierarchy (BVH) for improved performance during pair detection.

Link copied to clipboard

Enforces rectangular boundary constraints on a physical body within a simulation.

Link copied to clipboard

A class that implements collision resolution between two bodies in a simulation using a Sweep and Prune (SAP) algorithm. This constraint resolves collisions by identifying and responding to intersections between the boundary nodes or edges of the two bodies.

Link copied to clipboard
class Triangle(var a: Int, var b: Int, var c: Int)

Represents a triangle defined by three node indices in a physical simulation.

Link copied to clipboard
class TriangleAreaConstraint(val body: Body, var compliance: Double = 0.0, var iterations: Int = 1) : Constraint

Represents a constraint that maintains the area of triangles within a physical body.

Functions

Link copied to clipboard
fun Body.bodyAreaConstraint(configure: BodyAreaConstraint.() -> Unit = {})

Adds a body area constraint to the body, ensuring that its area remains close to a target rest area during simulation. The constraint includes compliance and uses iterative solving to maintain this condition.

Link copied to clipboard

Adds a BoundaryNodeRelaxForce to the Body's list of forces. This force acts on the boundary nodes of the body to relax their positions by adjusting their velocities based on neighboring node positions.

Link copied to clipboard
fun contourToBody(contour: ShapeContour, density: Double = 10.0, linkNeighbors: Int = 1, configure: Body.() -> Unit = {}): Body

Converts a given shape contour into a physical body representation with configurable nodes and links.

Link copied to clipboard
fun findCollisions(nodes: List<Node>, solveCollision: (Int, Int) -> Unit)
Link copied to clipboard
fun findOverlappingPairs(rectangles: List<Rectangle>): List<Pair<Int, Int>>
Link copied to clipboard
fun Body.gravity(configure: GravityForce.() -> Unit): Boolean

Adds a gravitational force to the body and allows configuring its properties.

Applies a gravitational force to the body by adding it to the list of forces acting on the body.

Link copied to clipboard
Link copied to clipboard
fun Body.manyNodeForce(configure: ManyNodeForce.() -> Unit)
Link copied to clipboard

Configures the force simulation to use the naive broad-phase collision detection algorithm.

Link copied to clipboard

Applies a circular constraint to the nodes of this Body.

Link copied to clipboard

Adds a node collision constraint to the body, configuring it using the provided lambda.

Link copied to clipboard

Applies a node contour constraint to the body and configures it using the provided configuration block.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Adds a NodeRepulseInterbodyForce to the list of interbody forces in the simulation.

Link copied to clipboard

Adds a repulsive interbody force using a bounding volume hierarchy (BVH) to the simulation.

Link copied to clipboard
fun pointsToBody(points: List<Vector2>, radius: Double = 1.0, configure: Body.() -> Unit): Body

Creates a physical body from a list of points, with nodes initialized based on the specified radius, and applies a configuration to the resulting body.

Link copied to clipboard

Adds a rectangular boundary constraint to the body, ensuring that its nodes remain confined within a specified rectangular region during the simulation.

Link copied to clipboard

Sets the collision resolution handler to a sweep-and-prune (SAP) based collision constraint.

Link copied to clipboard
fun sortAndSweepBipartite(points: List<BoxedPointOrEdge>, edges: List<BoxedPointOrEdge>, onIntersect: (Int, Int) -> Unit)

Processes a collection of points and edges in a bipartite structure using a sweep-line algorithm to detect and handle intersections. The method categorizes objects into active points and edges, iteratively updates the active lists, and invokes the intersection callback when overlaps are detected.

Link copied to clipboard

Adds a triangle area constraint to the body, ensuring that the areas of triangles in the body remain consistent with their initial (rest) areas during simulation.