← Back to Work

Roadwright

Solving the Road an Arbitrary Drawn Wheel Rolls On
Role & Team
Creator & Sole Author
Timeline
Sep 2026 to Present
Stack
TypeScript, Canvas 2D, Web Audio, Vite
Verification
79 tests, accuracy to 1 part in 106

Overview

A square wheel rolls perfectly smoothly if you build the right road for it. That road is a row of inverted catenaries, and Stan Wagon rode a bicycle on one at Macalester College in 1997. Roadwright generalises that result to any closed shape a visitor draws, solving the road profile that carries the wheel with its axle at a constant height and animating the result at 60 fps.

Every prior artifact in this space is fixed: a square wheel and its one road, in a museum exhibit, in a 1992 issue of Mathematics Magazine, or in a demo with eight canned examples. Roadwright solves the inverse problem for arbitrary input, live, while the axle is being dragged. It ships with zero runtime dependencies at 18 kB gzipped.

The Mathematics

Represent the wheel in polar form as r(θ), the distance from the axle to the boundary at each angle. Holding the axle at constant height requires the contact point to sit directly beneath it at distance r, so the road height is y = −r. Enforcing rolling without slipping equates arc length along the road to arc length along the wheel, which reduces to dx = r dθ. The pair of relations follows:

x(θ) = ∫ r dθ, y(θ) = −r(θ), and inverting, θ(x) = ∫ dx / (−y).

Both directions are quadratures rather than iterative solves, so there is no convergence tolerance to defend and no solver to tune. That is what permits continuous recomputation during interaction, in contrast to the roughly 800 ms Web Worker solve that Eigendrum requires for its eigenvalue problem.

A periodic road admits a closed wheel only when the total turn over one period is exactly 2π, giving the closure condition ∫ dx / (−y) = 2π.

Verification

Correctness is asserted by test against closed-form results rather than by inspection. All 79 tests run in CI on every commit.

  • A square wheel of half-side a returns y = −a cosh(x/a) to better than 1 part in 106.
  • A circle returns a flat road, to 5×10−6 at 2048 segments.
  • Road arc length equals wheel perimeter, which is the definition of rolling without slipping.
  • The forward and inverse maps round-trip, so the road remains a valid inverse of the wheel.
  • Contact angle is derived from the same cumulative integral as position, which structurally prevents visible slip.

One non-obvious result: the road's horizontal period is not the wheel perimeter. For a square of half-side a the road spans 8a ln(1+√2) ≈ 7.0509a against a perimeter of 8a. Road arc length is the quantity that matches. Only a circle makes the two coincide, and conflating them is the most likely error in this problem class.

Two Engineering Problems Worth Naming

Admissibility. A wheel is only well posed when a ray from the axle meets the boundary exactly once in every direction, meaning the region is star-shaped about the axle. Most freehand input violates this. The permissible axle region is the polygon kernel, computed as a half-plane intersection and rendered as a hatched zone so the constraint is visible rather than latent; dragging is clamped to it, making an invalid axle unreachable. Where no kernel exists, the outline is resampled as a radial hull about its pole of inaccessibility, which contains the original and preserves every extremity while bridging the unseen pockets. The original is retained and displayed, so the adjustment is never silent.

Buildability. A profile can be exact and still impossible to fabricate: sufficiently sharp corners drive into the road as the wheel rotates. This is the established reason a rolling equilateral triangle cannot be constructed. Rut depth turns out to be a poor predictor, since a rounded rectangle has deeper ruts than a triangle and rolls cleanly. Roadwright instead measures interference directly by sweeping the wheel through a full period, reporting the maximum penetration as a fraction of axle height: 0% for a circle and square, 0.01% for a rounded rectangle, 4.7% for an equilateral triangle, and 21.5% for a five-pointed star. The figure is written into the SVG cut file as a fabrication warning.

Outputs

The road tilts to an arbitrary grade, which is exact rather than approximate: the derivation constrains the axle to a straight line and never invokes gravity, so nothing requires that line to be horizontal. An assembly view carries two independently rotating wheels on a chassis; a wheelbase of a whole number of road periods places them in identical orientation, which follows directly from the closure condition and is asserted by test.

Exports are a WebM loop recorded from the canvas, a PNG of the sheet, and an SVG cut file dimensioned in millimetres with a stated kerf. Shapes are shared through the URL fragment, which browsers do not transmit to servers, so drawn geometry never leaves the client.