ana HILBERT4
twist into w
anakata
what you're looking at

One unbroken path through every cell of the unit tesseract cut into a grid, each step to a cell that shares a face. Cut each cell again and the path is redrawn as sixteen copies of itself, one per sub-tesseract, joined end to end. The path is drawn as a hypertube: every point within the tube radius of it, in four dimensions.

Shadow shows the whole thing at once, w squashed into your three directions by perspective (the far side in w drawn smaller, the cube inside the cube). Slice shows only what your 3D slice cuts from the hypertubes, as solids. A tube running along your slice is cut into a tube; one crossing it is cut into a blob that appears, swells and vanishes as you move. Thicken the tubes to see more of them at once.

The pad (bottom left) twists your slice into w: hold it and your slice turns, and the cut sweeps through the tesseract. The lever (bottom right) moves your slice ana and kata. Let go and they spring back. Square up turns your slice back to w = constant. Keys: J L and I K twist, R F move, Z squares up, V swaps the view, space traces.

how it works

Number the cells along the path, 0 to 16b − 1, and write each number in base 16. The first digit says which of the tesseract's sixteen sub-tesseracts the cell is in, the next which sixteenth of that, and so on: each digit is a step deeper. The sixteen are visited in the order the order-1 path visits the tesseract's corners, a Gray code that flips one coordinate at a time in the ruler sequence w z w y w z w x w z w y w z w, ending one step along x from where it began. Each copy is turned and reflected so that it starts where the last one ended.

The coordinates come straight from the digits by John Skilling's bit tricks (Programming the Hilbert curve, 2004): a Gray decode and one sweep of reflections and exchanges, the same code for the square, the cube and the tesseract. Try 2 and 3 dimensions to calibrate your eye.

The slice is ray-traced. Every ray through your view lies in your slice; it is walked through the 4D grid cell by cell, and in each cell it's tested against the two half-tubes that leave the cell's centre for its neighbours on the path. In the slice, colour by w shows how far ana (teal) or kata (rose) of you each tube's core runs.

What the curve is for: cells near each other on the path are near each other in space, so sorting points by their place along it keeps neighbours together. That's how databases index maps and how renderers order their work. The converse fails: neighbours in space can be far apart on the path, across the seams between copies.

Checked: test/hilbert.selftest.mjs holds the path to visiting every cell once, stepping only to face-neighbours, starting and ending at corners one edge apart, inverting exactly, and being, at every scale, the coarser path with each cell replaced by a copy. It holds the slice's walk to brute force over every segment of the path.