A while ago the plan was to have at least 12 postscript based fractals so I could make some type of calendar; that is decorate each month with a different fractal image. Now I’m not sure what to think about the idea, a bit of a waste of time during covid, or an attempt at stretching one’s brain and trying to have fun at the same time.

The Hilbert curve is one of the more famous space filling curves out there. As per usual, I mostly care about the implementation and leave the analytical details to the various sites out there. Maybe one day I might try to implement the 3D version; surprisingly I stumbled upon this, so it might be ok.

The definition of the Hilbert curve is self-similar and recursive, that is higher iterations depend on previous iterations that have been transformed (using flips and rotations). The following video has a great explanation about Hilbert curves.

With the implementation, the initial shape is a ‘cup’ type of shape where 4 points are connected to their closest neighbouring points using 3 edges/lines.

Next, each section of the curve is replaced using the following set of rules (it might look a bit daunting but its not too bad):

Where, a particular type of shape is mapped to 4 other shapes (including itself) and the arrows correspond to the actual drawing of necessary line segments. Note that each mapping iteration requires that the line segment length to be reduced using the following formula; where \ell_0 is the original length, i is the iteration number, and \ell_i is the length at a specific iteration.

##### Implementation

Postscript code was written to generate the Hilbert curve at an arbitrary length and is available here. Below are two samples of the resulting output; on the left is an example with 7 iterations, while on the right show the sequence of the first 6 iterations.

Note, for a more creative touch, the line width can be adjusted. In the example on the right, the line width was chosen to be the same as the resulting white space.

##### Other Links

Since the Hilbert curve is fairly famous, it has been implemented by many others over the years. Here are some of my favourites:

- This fabric looks amazing; I especially like the pillows
- Someone knitted a Hilbert curve afghan/blanket
- This site has an online tool to generate Hilbert curves very easily
- There is this portrait of David Hilbert that pretty cool
- This video really explains a lot of details about space filling curves quite well.
- Finally, someone made a 3d Hilbert curve out of plumbing supplies.

## No Comments