Search code examples
pythonalgorithm3dhilbert-curve

Algorithm for generating a 3D Hilbert space-filling curve in Python


I'd like to map points in a RGB color cube to a one-dimensional list in Python, in a way that makes the list of colors look nice and continuous.

I believe using a 3D Hilbert space-filling curve would be a good way to do this, but I've searched and haven't found very helpful resources for this problem. Wikipedia in particular only provides example code for generating 2D curves.


Solution

  • This paper seems to have quite a discussion: An inventory of three-dimensional Hilbert space-filling curves.

    Quoting from the abstract:

    Hilbert's two-dimensional space-filling curve is appreciated for its good locality properties for many applications. However, it is not clear what is the best way to generalize this curve to filling higher-dimensional spaces. We argue that the properties that make Hilbert's curve unique in two dimensions, are shared by 10694807 structurally different space-filling curves in three dimensions.