Constraints


The essence of constraint is projection.

Find the minimum movement that satisfies the constraint.

Basic Distance Constraint

The most basic constraint is the distance constraint

function ConstrainDistance(point, anchor, distance) { return ((point - anchor).normalize() * distance) + anchor;
}

It is satisfied by projecting the point onto a circle around the anchor.

Distance Constraint Chain

As with all constraints, distance constraints can be chained together

The order in which constraints are satisfied is important. The ones here are solved stepping away from the mouse, which pulls them towards the mouse.

FABRIK Chain

If the distance constraints are first solved in one direction, and then the other, it creates a form of Inverse Kinematics called “FABRIK”, or “Forwards and Backwards Reaching Inverse Kinematics”.

Collision Constraint

Distance Constraints can also be used to separate

Collision Constraints with Verlet

If the constraints act symmetrically (where each participant steps half-way towards satisfying the constraint), then one can simulate physics by adding momentum with Verlet Integration.

Verlet Rope

Solving constraints sequentially is called the Gauss-Seidel Method. It converges faster, but it is not technically correct.

Full Source

Volume Preserving Soft Body

The alternative is to average the contributions from each constraint before applying them. This is the Jacobi Method. It is more stable, and makes it so the order does not matter. However, it is “squishier” because it converges more slowly.

If one wraps the rope above into a circle, and constrains the shape’s volume, one can create a volume preserving soft-body

Full Source

The Jacobi Method is useful for keeping phantom forces from appearing in complex systems like this one.

This light introduction to constraints is the first in (hopefully) a series of blog posts exploring the power of simple mathematics.