One Line, No Lifting the Pen: Hilbert's 1891 Curve and Your Grasshopper Point Order
Peano found it in 1890, Hilbert drew it in 1891. Why the space-filling curve's locality orders drill points, print infill and robot targets in Grasshopper.
A line has no width. It is the thinnest object geometry owns, the thing you draw before you draw anything else. And yet there is a single continuous line that, folded finely enough, passes through every point of a square: every point of a façade panel, every point of a floor plate, with no gaps left over. Write that sentence on a whiteboard in a Zürich studio and someone will say it cannot be true. In 1890 most mathematicians would have agreed with them.
This is a foundation piece about that line, the Hilbert curve, and about the one property that makes it useful 135 years after David Hilbert drew it: locality. Things that sit near each other in the list sit near each other on the plane. That is all a drill, a print nozzle or a robot arm needs to hear.
What it is:
A space-filling curve is a continuous map from a line segment onto a two-dimensional region. In plain office terms: one path, never lifted, that eventually visits the whole area. You never see the finished curve. You only ever build approximations of it, and each approximation is a perfectly ordinary polyline that walks through a grid of cells one neighbour at a time.
The Hilbert construction is recursive and easy to hold in your head. Split the square into four quarters. Walk them in a U shape: bottom-left, top-left, top-right, bottom-right. Then replace each quarter with a smaller copy of the whole U, rotated or mirrored so that the exit of one quarter lands next to the entrance of the next. Repeat. At order 1 you have 4 cells; at order 5 you have 1,024. The path never jumps, because the rotations were chosen precisely so that it would not have to.
Why it works:
The shock behind the curve is set theory. Georg Cantor had shown that a line segment and a square contain the same number of points, a result that unsettled people who thought dimension was something you could count. Cantor’s matching, though, tears the line to shreds. The question Giuseppe Peano answered was sharper: can the matching be continuous, so that a pen moving smoothly along the segment covers the whole square? It can. Felix Hausdorff, writing in Grundzüge der Mengenlehre in 1914, called it, according to the MacTutor History of Mathematics archive at St Andrews, “one of the most remarkable facts of set theory.”
The price of continuity is that the map cannot be one-to-one. A continuous bijection from an interval onto a square would make the two shapes topologically identical, and Netto’s theorem rules that out. Some points of the square are therefore visited more than once by the limiting curve. For a designer this detail is harmless, because you only ever work with a finite approximation, where every cell is visited exactly once.
The property that matters on the desk is the arithmetic of those approximations. In a unit square, the order-n Hilbert polyline has length 2n − 1/2n. Each order quadruples the number of cells and roughly doubles the length, while the area it covers never changes. That is the geometric heart of the thing: length grows without bound, area stays fixed, and the step between consecutive points is always exactly one cell. Mathematicians describe the curve as preserving locality “fairly well”. The honest small print is that the converse does not always hold: two cells that touch across a quadrant boundary can sit far apart in the list. Norbert Wiener noticed in 1933 that such curves could reduce Lebesgue integration in higher dimensions to integration in one dimension, which is the same idea in its purest form: flatten the plane into a line without losing who your neighbours are.
We ran the number ourselves, in a short Python 3 test on 13 November 2026. On a 1 m × 1 m panel at order 5, the grid holds 1,024 cells of 31.25 mm. The Hilbert path through all of them measures 31.97 m, and every single step is one cell to an adjacent neighbour. The same 1,024 cells visited in Z-order (Morton order, the “obvious” ordering you get by interleaving the bits of x and y) give a 51.55 m path, with jumps of up to 31 cells, about 0.97 m. That difference is not a shortest-path result; Hilbert order is good, not optimal, and the travelling-salesman problem is a different and much harder question. But 19.58 m of avoidable idle travel per panel is the kind of number a fabrication team notices.
←TODAY: In 2026 PrusaSlicer ships Hilbert infill and Google’s S2 library indexes the whole Earth along Hilbert curves down to ~1 cm cells.
→3012: In Zurich-3012 every machine that visits points, from drill to drone, inherits a sorting rule first drawn on two pages in 1891.
Fulcrum: A proof meant to unsettle intuition about dimension turned out to be the most practical travel plan a toolhead ever got.
Origins:
Peano published first: “Sur une courbe, qui remplit toute une aire plane,” Mathematische Annalen 36 (1890), pages 157–160. His construction was entirely analytic, built from ternary expansions, and it carried no picture. A reader had to trust the algebra. Peano, born in Cuneo in 1858 and working in Turin, was a builder of formal language for mathematics as much as a geometer; his axioms for the natural numbers are still taught.
A year later David Hilbert, then a Privatdozent at Königsberg and four years away from his chair at Göttingen, published “Über die stetige Abbildung einer Linie auf ein Flächenstück,” Mathematische Annalen 38 (1891), pages 459–460. Two pages. What Hilbert added was the picture: four quarters, each a rotated copy of the whole, refined step by step. Per the Wikipedia survey of space-filling curves, his note was the first to include a figure helping to visualise the construction technique. That figure is the reason designers know his name rather than Peano’s. A proof you can see is a proof you can program.
It is worth saying plainly what both men gave us. Peano found that the object exists. Hilbert made it legible, and legibility is what lets a 25-year-old rebuild a method from its principle instead of from somebody’s file. From where this desk sits, looking back from the late 2070s, that is the part of computational design that survived every software generation: the derivation, written down.
The curve then waited decades for its machines. Databases adopted it as an alternative to Z-order for multidimensional indexing and R-tree packing. Printer slicers adopted it as an infill pattern. Prusa Research’s own help pages describe Hilbert infill as a “rectangular labyrinth” whose print time lands “somewhere between honeycomb and rectilinear,” and note that as a top layer it “looks more like a wicker basket.” Google’s S2 geometry developer guide states that “the S2 curve is based on the Hilbert curve”: six Hilbert curves on the six faces of a cube form a single continuous loop over the entire sphere, with 30 levels of refinement ending in leaf cells about 1 cm across on the Earth’s surface. The guide credits the construction with significantly improving locality of reference. The people who wrote those slicers and those geodesy libraries mostly go unnamed; their work is invisible exactly because it functions every time someone prints a bracket or opens a map.
In practice:
The landing for a Swiss office is any list of points that a machine, or a person, will visit in order. A façade consultant in Zürich with 400 anchor holes on a perforated aluminium panel. A timber engineer in Bern sending fixing points for a CLT wall to a robot cell. A BIM coordinator bucketing a point cloud from a site scan so that neighbouring points sit together in memory and load together. In each case the points usually reach the machine in whatever order Grasshopper produced them: the order of a data tree, of a division, of an intersection. That order is an accident of the definition, not a decision anyone took.
Sorting along a Hilbert order turns the accident into a rule you can name in a review. It costs a few lines of recursion in a Grasshopper Python 3 component; there is no need for a dedicated plugin, and the script stays readable on the canvas. The trade-off is real: Hilbert order keeps jumps short on average, not in the worst case, so a panel with holes clustered along a quadrant seam can still produce one long move, and a toolpath for a CNC router with strict entry rules may need its own planner. PAZ has already shown that a grammar of a few lines can grow a structure in Grasshopper; this is the same lesson pointed at sequence instead of form.
Atelier: Offices adopting AI-assisted fabrication scripts tend to receive point lists in whatever order the generator emits, and nobody owns the sequence. Make the sequence an explicit, written rule. Monday move: add one Hilbert-sort component in front of every drilling or fixing export in your template definition, and log the total travel length before and after.
Hack: Sort a panel’s drill points along a Hilbert order so the machine always steps to a neighbour. Paste this into a Grasshopper Python 3 component with inputs P (points in panel-local coordinates, origin at the corner) and c (cell size, e.g. 31.25 for a 1,000 mm panel at order 5). The function turns each cell’s (x, y) into its distance along the curve, quadrant by quadrant, rotating as Hilbert did; the last line is the sort.
def hkey(x, y, n):
d, s = 0, n // 2
while s: rx, ry = (x & s) > 0, (y & s) > 0; d += s * s * ((3 * rx) ^ ry); x, y = (x, y) if ry else ((n-1-y, n-1-x) if rx else (y, x)); s //= 2
return d
a = sorted(P, key=lambda p: hkey(int(p.X // c), int(p.Y // c), 32))Feed a into a Polyline component and measure its length against the unsorted list. The 32 is the grid width, 25; raise it to 64 for order 6 and halve c to match.
Hilbert drew two pages so that others could see the construction. Return the favour in your own definitions: open your most-used fabrication export, sort its points along a Hilbert order, and write the rule next to the component so the next person can rebuild it from the principle, not the file.
PAZ Kaffi · multidisciplinary editorial, led by PAZ Academy