• Jan 30, 2026
  • 4 min read

Interactive Physics: A Double Pendulum and a Slider-Crank You Can Play With

Built in 2023, revisited now: what I made, and what I’d do differently today.

I’m an engineer by training, and some ideas only click when you can move them yourself. A textbook figure of a double pendulum tells you it’s chaotic. A slider you drag to change the starting angle by one degree, and watch the path become something completely different, shows you.

In 2023 I built two small apps around that idea.

1. The double pendulum: chaos you can poke

Hang a second pendulum from the end of the first. Two rods, two masses, gravity. That’s all. And yet its motion is the textbook example of chaos:

  • It’s deterministic. The same starting conditions always give exactly the same motion.
  • It’s unpredictable in practice. A tiny difference in the starting angle grows until the two paths have nothing in common.

The app lets you change the starting conditions and watch the motion. Run it twice with angles that differ by a fraction of a degree and the two runs start out identical and end up unrelated. That’s the whole point, and no paragraph explains it as well.

How it works. The equations of motion for the two angles come from classical mechanics (a Lagrangian derivation). They give the angular accelerations as functions of the angles and angular velocities. The app integrates those numerically with NumPy and draws the result with Plotly, in a Streamlit interface. Jake VanderPlas’s well-known write-up of a triple pendulum was the inspiration; I wanted something people could use without reading any code. The code is on GitHub.

The same idea explains why weather forecasts stop being useful after a week or two, and why planning a trip months ahead works better with typical patterns than with a forecast. That’s exactly what the trip planner does.

2. The slider-crank: why a piston never cruises

The slider-crank is three parts: a crank that rotates, a connecting rod, and a slider that moves in a straight line. It turns rotation into back-and-forth motion, or the reverse. It’s in every piston engine, in reciprocating pumps and compressors, and in mechanical presses.

The interesting part is that the slider’s speed isn’t constant, even when the crank turns at a perfectly steady rate. It stops at each end, speeds up, slows down, and the speed profile depends on the ratio between the crank and the rod length. It isn’t even symmetric: with a real connecting rod, the piston turns around faster at the top of its stroke than at the bottom.

The app, built with Dash, lets you see the mechanism move and how the slider’s speed changes through each turn. It ran in a container, first on Google Cloud Run and later at home. The code is on GitHub.

The 2023 version came out of a bigger idea: a small framework for describing mechanisms by their topology (which links connect to which joints) so the same code could animate an engine, a pump or anything else built from linkages.

What I’d do differently now

  • Run the physics in the browser. Both simulations are a few hundred lines of arithmetic. In JavaScript they’d run on the visitor’s own device: no Python server, no container, no hosting bill, nothing to keep alive at home. That’s how I build interactive explainers now: one HTML file each.
  • Show the divergence directly. For the pendulum, draw two pendulums at once with almost the same start, and plot the distance between them. Chaos becomes a curve that shoots upward.
  • Check the integrator. Simple fixed-step methods let the energy drift over long runs. A higher-order or adaptive solver (RK4, or SciPy’s solve_ivp) keeps a long simulation honest.
  • Cut the philosophy. The 2023 post spent paragraphs on butterflies and toast. The app made the point better than any of them.

Takeaways

  • Interactive beats illustrated for anything that changes over time.
  • Chaos isn’t randomness. It’s sensitivity to the start, and a slider shows it in seconds.
  • The simplest mechanisms hide the most interesting behaviour.
  • Put small simulations in the browser. Nothing to host, and they work offline.