Clever Quest Lab ← Labs

Physics Sandbox

Stack it, swing it, knock it all down.

Pick a tool, then press or drag on the scene. Keyboard: tool letters (G, B, C, L, P, R, O, S, X, E), arrow keys move a cursor, Enter starts and finishes an action, Esc cancels, Space pauses.

Presets

Readouts

Shapes
0
Asleep
0
Joints
0
Contacts
0
Kinetic energy
0 J
Total energy
0 J
Time
0.0 s
Frames per second
–

World

Springs and new shapes

How to use it

Pick a preset and start poking it. Grab is the default tool: press on a shape, drag it and let go to throw it. The other tools build things: draw a box or a ball by dragging, draw a fixed line as a ramp or a shelf, pin a shape to whatever lies behind it, and connect two shapes (or a shape and the background) with a rod, a rope or a spring. Delete removes one shape or joint. Explode blasts nearby shapes away. Pause, Step and Slow motion help you study a fast collision, and Reset rebuilds the current preset.

Controls

How it works

Every shape is a rigid body with a position, an angle, a velocity and a spin. The engine repeats the same loop 120 times per simulated second. First it integrates: gravity changes each velocity, then each velocity moves its body. This order, called semi-implicit Euler, is not exact, but it is cheap and stable.

v ← v + g·Δt,   x ← x + v·Δt,   Δt = 1/120 s

Then it looks for collisions. A broad phase sorts the bounding boxes of all shapes along the x-axis, so only neighbours are compared exactly. Two boxes are tested with the separating axis theorem: if their shadows on any of the four face directions do not overlap, they cannot touch. Otherwise the direction of smallest overlap is the contact normal, and clipping one edge against the other face gives up to two contact points.

At each contact point the engine applies an impulse, a sudden change of momentum, along the normal:

j = −(1 + e)·vn / (1/mA + 1/mB + (rA×n)²/IA + (rB×n)²/IB)

Here vn is the speed at which the two surfaces approach, e is the bounciness (coefficient of restitution), m and I are mass and moment of inertia, and r points from each centre of mass to the contact. With e = 0 the bodies stop approaching; with e = 1 they separate as fast as they came. Friction is a second impulse along the surface, limited by Coulomb’s law: |jt| ≤ μ·j.

Why stacks are hard. In a tower every contact depends on all the others: the bottom box carries the whole weight above it, yet each impulse is computed from one contact alone. So the engine sweeps over all contacts eight times per step (sequential impulses) and starts each step from the impulses of the previous one (warm starting). A separate correction pushes small overlaps apart without adding energy. Without these tricks a stack would sink, jitter or creep apart.

Constraints. Joints use the same machinery. A pin keeps two points together, a rod keeps a fixed distance and a rope pulls only when it is fully stretched. A spring follows Hooke’s law, F = −k·x, plus a damping force against the motion. Shapes that stay still for a while fall asleep and are skipped until something touches them.

Things to try

Frequently asked questions

Why do stacked boxes overlap by a hair?

The solver tolerates about 5 mm of overlap so that resting contacts do not flicker on and off. And with eight sweeps per step, a very tall stack is never perfectly rigid.

Is energy conserved?

Only in ideal cases, such as a pendulum on a rod or the frictionless, fully elastic cradle. Friction and collisions with bounciness below 1 remove kinetic energy, which a real object would turn into heat and sound. The Total energy readout adds height and stretched springs to the kinetic energy.

Why do slow impacts not bounce?

Below an approach speed of 0.5 m/s bounciness is switched off. Otherwise shapes resting under gravity would keep trembling instead of settling.

Can a fast shape pass through a thin line?

Occasionally. Shapes move in steps of 1/120 s, so a small, fast one can jump across a thin line. Speed is capped at 30 m/s to make this rare, and the outer walls are too thick to cross.

How many shapes can I add?

Up to 250 shapes and 200 joints. Shapes at rest are asleep and cost almost nothing.

More free games and simulators