Saramsha

No. 056  ·  11 November 2026

Your Hand Shakes, the Curve Doesn't

A mouse stroke is a few hundred raw samples, and every one of them wobbles — your hand, the sensor, both. Draw below and watch an algorithm from 1973 throw out almost all of those points without changing the shape, then watch a second one fit a smooth curve through whatever is left. What comes out the other end is real exportable SVG.

Draw with mouse or finger, like a signature — lift and draw again to add more strokes. Clear to start over.

About this piece

Two algorithms, forty years apart, doing one job

Move a mouse or a finger across a screen and the browser hands you its position dozens of times a second — every tremor of your hand included. A three-second signature can easily be three hundred points, and almost none of them matter: most sit so close to a straight line between their neighbours that removing them changes nothing you'd notice. The question is which ones are safe to throw away, and that turns out to have a clean answer.

Ramer–Douglas–Peucker simplification (Urs Ramer, 1972; David Douglas and Thomas Peucker, 1973 — the two groups published within a year of each other, unaware of one another, which is usually a sign an idea was waiting to be found) answers it by recursion. Take the straight line between a stroke's first and last point. Find whichever point strays furthest from that line. If the furthest point is close enough — inside the tolerance you're dragging on the right — every point between the ends can be dropped; a single line already stands in for all of them. If it's too far, that point is kept and the same question is asked again on each half it splits the stroke into. The recursion bottoms out with a short list of points that were each, at some stage, the worst offender on their stretch of the line — which is exactly the corners and cusps a person would point to by eye. The algorithm was built for a different problem entirely: thinning the digitised coastlines and contour lines on paper maps, where every extra point cost real money to store on 1970s hardware. The tolerance slider here is that same distance, just measured in screen pixels instead of map metres.

Filling the gaps back in, smoothly

Simplification alone would leave you with straight segments meeting at hard corners — a polygon, not a signature. The bold curve layer runs a second step: a Catmull–Rom spline, converted into a chain of cubic Bezier curves, one per surviving gap. Each curve's two control points are set from its neighbours on either side, which is what makes the join between curves disappear — the spline's direction coming into a point matches its direction leaving, so there's no visible seam. This is the same construction Illustrator's pencil tool, Apple's Pencil-smoothing and most vector-tracing software reach for: simplify first, then interpolate, because fitting a smooth curve through every raw point would just curve-fit the jitter right back in.

The width layer is a smaller trick riding on data the first two throw away: each raw point keeps its own timestamp, so the gap between any two kept points also has a measured duration. Divide distance by time and you get a speed for every stretch of the stroke, slow where a calligraphy pen would dig in and fast where it would lift and skim — so the line can be drawn thick where you slowed down and thin where you didn't, with no pressure sensor involved at all.

Distance-to-line uses the perpendicular distance to the infinite line through the segment's endpoints, the standard Douglas–Peucker measure, not the distance to the segment itself. The exported SVG is the literal chain of cubic Bezier commands drawn on screen, re-scaled to the canvas's own coordinate space — what you download is what you see, not a re-render.