Brachistochrone racer

Jul 28, 2026physicscs

Sample project writeup — replace with a real one. Its physics + cs tags land it between chalkboard and terminal: dark, with dust and a faint grid.

Given two points, what curve gets a frictionless bead from the top one to the bottom one fastest under gravity? Not the straight line — Bernoulli's 1696 challenge, and the answer that launched the calculus of variations: the cycloid, the path traced by a point on a rolling wheel's rim.

This project is a small browser simulator that races beads down a straight line, a circular arc, a user-drawn curve, and the cycloid, side by side. Watching the cycloid bead dive steeply to build speed early — and still arrive first despite the longer path — does more for intuition than the derivation ever did for me.

The one equation that matters

Energy conservation fixes the speed at any depth: v=2gyv = \sqrt{2gy}. So the total time along a curve y(x)y(x) is the functional

T[y]=0x11+y22gydx,T[y] = \int_0^{x_1} \frac{\sqrt{1 + y'^2}}{\sqrt{2gy}} \, dx ,

and minimizing it with the Euler–Lagrange machinery (the integrand has no explicit xx, so the Beltrami identity applies) gives y(1+y2)=2ry\,(1 + y'^2) = 2r — the differential equation of a cycloid of rolling radius rr.

Simulation notes

The integrator is a plain RK4 on arc length, not a physics engine — each curve is arc-length parameterized, and the bead's state is (s,s˙)(s, \dot{s}) with s¨=gsinθ(s)\ddot{s} = g \sin\theta(s) from the local slope. Two details bit me:

  1. The cycloid through two arbitrary points requires solving a transcendental equation for the rolling radius; Newton's method on y1x1=1cosϕϕsinϕ\frac{y_1}{x_1} = \frac{1 - \cos\phi}{\phi - \sin\phi} converges in a handful of iterations from a decent bracket.
  2. The straight-line bead must not win at shallow angles due to integration error — a good end-to-end test is checking the analytic straight-line time 2L2/(gy1)\sqrt{2L^2 / (g\,y_1)} against the simulated one.