Aller au contenu principal

Constraints

Constraints are rules that define the relationships between particles. They are the core mechanism for building structures. This page introduces the main constraints available.

DistanceConstraint​

Forces two particles to maintain a specific distance from each other. This is the most common constraint.

<DistanceConstraint from="p1" to="p2" />

CollisionConstraint​

Prevents two particles from overlapping, based on their style.radius.

<Point id="p1" pos={new Vec2(240, 100)} style={{ radius: 20 }} />
<Point id="p2" pos={new Vec2(260, 100)} style={{ radius: 20 }} />
<CollisionConstraint from="p1" to="p2" />

PinConstraint​

Fixes a particle to a specific point in space. This is useful for creating anchor points.

This is achieved via the pinned prop on the <Point> component.

<Point id="anchor" pos={new Vec2(250, 100)} pinned />

AngleConstraint​

Maintains the initial angle between three particles.

<AngleConstraint from="p1" center="p2" to="p3" stiffness={0.1} />

MinMaxDistanceConstraint​

Keeps the distance between two particles within a certain range.

<MinMaxDistanceConstraint from="p1" to="p2" minDistance={50} maxDistance={150} />

MinMaxAngleConstraint​

Keeps the angle between three particles within a specific range in radians.

<MinMaxAngleConstraint from="p1" center="p2" to="p3" minAngle={Math.PI/2} maxAngle={Math.PI} />

PlaneConstraint​

Forces a particle to stay on one side of an infinite plane (a line in 2D).

<PlaneConstraint particle="ball" origin={new Vec2(0, 300)} normal={new Vec2(0, -1)} />