Visualizations
244 / 500

244 · Physics

Truss Bridge Builder

Draft a bridge on blueprint paper, then send a truck over as each beam shows its stress.

Every member is a stiff spring between pin joints, solved with XPBD: 24 substeps a frame, each projecting the beams back toward their rest lengths with a compliance taken from the axial stiffness EA / L. Because the solve is physical, each constraint's Lagrange multiplier is that member's real axial force, so blue means tension and red means compression. A beam pulled past its strength snaps and both halves swing free; in compression the limit is Euler buckling, which falls with 1 / L squared, so long struts fold at a hinge first. The truck is two wheel particles on a rigid chassis whose contacts push on the deck through the same solver, and with no input an autopilot drafts Warren, Pratt and under-deck trusses plus one doomed plain deck, then tests each.

Try it. Drag from any joint to add a member, snapped to the grid and to existing joints (Road members carry the truck, Beams do not). R and B pick Road or Beam. Click a member to delete it, Backspace undoes. Test (or space) sends the truck across; 1 to 4 load the classic designs, C clears.

  • XPBD
  • Euler buckling
  • Truss analysis
  • Contact constraints

View the source · one module, plus a small shared runtime for sizing, the animation loop and input

Build your own

Paste this into Claude Code, Codex or any coding agent to get a simple version running, then take it wherever you like.

Build a little truss bridge simulator with JavaScript and the HTML canvas element. Put everything in a single index.html file with no libraries or build step, so I can open it directly in a browser.

Start simple:
- Make a canvas that fills the window, stays sharp on high-DPI screens (scale by devicePixelRatio), and resizes with the window. Draw two cliffs with a gap between them and a grid of snap points over the gap.
- Store a bridge as joints (x, y, and whether it is a fixed anchor on a cliff) and members (two joint indices and a rest length).
- Let me drag from a joint to a grid point to add a member, up to a maximum length, and click a member to delete it.
- Press space to simulate. Use position-based dynamics: each step, add gravity to every free joint's velocity and move it, then loop over the members several times and push each pair of joints back toward the rest length. Derive velocity from how far each joint moved. Use 10 to 20 small substeps per frame.

Once that works, make it beautiful and physical:
- Track how hard each member had to correct per substep (its constraint force). Color tension blue, compression red and idle members pale gray, and break any member that goes past a limit.
- Make compression members weaker the longer they are (Euler buckling scales with 1 / length squared).
- Add a truck: two wheel particles held a fixed distance apart, pushed out of the deck members they touch, driving right at a steady speed. Its weight should light up the bridge.
- Draw the editor as blueprint paper and the test as a sunset canyon.

Explain the key ideas in short code comments. When you're done, tell me how to open it and suggest three directions I could take it next, such as a budget and score per level, switching to XPBD so stiffness no longer depends on the iteration count, or an autopilot that searches for the cheapest bridge that holds.
PreviousRRT* ParkingA self-driving car grows a tree of curved manoeuvres, then reverses into its spot. NextPond DropA drop of pond water under a brightfield microscope, with a focus knob you can turn.

Related visualizations

  • Tensegrity3D Struts that never touch, floating in a web of cables, found by dynamic relaxation.
  • Rigid BodiesPhysics Stacked towers of boxes knocked down by a swinging wrecking ball.
  • Gear Train WorkshopPhysics A blueprint bench where involute gears snap into mesh, drive clocks and jam.
  • Hanging Chain ArchesPhysics Hang chains and weights, then flip the sheet to turn them into stone arches.
  • Tearable ClothPhysics A sheet of Verlet points and springs that sags, swings and rips.
  • Marimba Bar TunerPhysics Carve a rosewood bar while a finite element solver retunes its overtones to 1:4:10.
  • Balancing MobileAlgorithms A red-black or AVL tree hangs as a spring-physics mobile while a plain BST droops.
  • Drying MudSimulation Wet clay dries and cracks into a lakebed of curling plates, primaries first.
  • Blocks World PlannerAlgorithms A robot arm plans with A* over STRIPS states, then stacks the blocks to match your goal.

Use ← and → to move between demos. While the canvas has focus, keys go to the demo instead.

← More from Emergent Mind Labs