Sponsored Links
-->

Saturday, May 12, 2018

Hilbert curve with n=5 | On a 5x5 grid. There are 86 such cu… | Flickr
src: c1.staticflickr.com

A Hilbert curve (also known as a Hilbert space-filling curve) is a continuous fractal space-filling curve first described by the German mathematician David Hilbert in 1891, as a variant of the space-filling Peano curves discovered by Giuseppe Peano in 1890.

Because it is space-filling, its Hausdorff dimension is 2 {\displaystyle 2} (precisely, its image is the unit square, whose dimension is 2 in any definition of dimension; its graph is a compact set homeomorphic to the closed unit interval, with Hausdorff dimension 2).

H n {\displaystyle H_{n}} is the n {\displaystyle n} th approximation to the limiting curve. The Euclidean length of H n {\displaystyle H_{n}} is 2 n - 1 2 n {\displaystyle \textstyle 2^{n}-{1 \over 2^{n}}} , i.e., it grows exponentially with n {\displaystyle n} , while at the same time always being bounded by a square with a finite area.


Video Hilbert curve



Images


Maps Hilbert curve



Applications and mapping algorithms

Both the true Hilbert curve and its discrete approximations are useful because they give a mapping between 1D and 2D space that fairly well preserves locality. If (x,y) are the coordinates of a point within the unit square, and d is the distance along the curve when it reaches that point, then points that have nearby d values will also have nearby (x,y) values. The converse can't always be true. There will sometimes be points where the (x,y) coordinates are close but their d values are far apart.

Because of this locality property, the Hilbert curve is widely used in computer science. For example, the range of IP addresses used by computers can be mapped into a picture using the Hilbert curve. Code to generate the image would map from 2D to 1D to find the color of each pixel, and the Hilbert curve is sometimes used because it keeps nearby IP addresses close to each other in the picture.

A grayscale photograph can be converted to a dithered black-and-white image using thresholding, with the leftover amount from each pixel added to the next pixel along the Hilbert curve. Code to do this would map from 1D to 2D, and the Hilbert curve is sometimes used because it does not create the distracting patterns that would be visible to the eye if the order were simply left to right across each row of pixels. Hilbert curves in higher dimensions are an instance of a generalization of Gray codes, and are sometimes used for similar purposes, for similar reasons. For multidimensional databases, Hilbert order has been proposed to be used instead of Z order because it has better locality-preserving behavior. For example, Hilbert curves have been used to compress and accelerate R-tree indexes (see Hilbert R-tree). They have also been used to help compress data warehouses.

Given the variety of applications, it is useful to have algorithms to map in both directions. In many languages, these are better if implemented with iteration rather than recursion. The following C code performs the mappings in both directions, using iteration and bit operations rather than recursion. It assumes a square divided into n by n cells, for n a power of 2, with integer coordinates, with (0,0) in the lower left corner, (n - 1, n - 1) in the upper right corner, and a distance d that starts at 0 in the lower left corner and goes to n 2 - 1 {\displaystyle n^{2}-1} in the lower-right corner.

These use the C conventions: the & symbol is a bitwise AND, the ^ symbol is a bitwise XOR, the += operator adds on to a variable, and the /= operator divides a variable. The handling of booleans in C means that in xy2d, the variable rx is set to 0 or 1 to match bit s of x, and similarly for ry.

The xy2d function works top down, starting with the most significant bits of x and y, and building up the most significant bits of d first. The d2xy function works in the opposite order, starting with the least significant bits of d, and building up x and y starting with the least significant bits. Both functions use the rotation function to rotate and flip the (x,y) coordinate system appropriately.

The two mapping algorithms work in similar ways. The entire square is viewed as composed of 4 regions, arranged 2 by 2. Each region is composed of 4 smaller regions, and so on, for a number of levels. At level s, each region is s by s cells. There is a single FOR loop that iterates through levels. On each iteration, an amount is added to d or to x and y, determined by which of the 4 regions it is in at the current level. The current region out of the 4 is (rx,ry), where rx and ry are each 0 or 1. So it consumes 2 input bits, (either 2 from d or 1 each from x and y), and generates two output bits. It also calls the rotation function so that (x,y) will be appropriate for the next level, on the next iteration. For xy2d, it starts at the top level of the entire square, and works its way down to the lowest level of individual cells. For d2xy, it starts at the bottom with cells, and works up to include the entire square.

It is possible to implement Hilbert curves efficiently even when the data space does not form a square. Moreover, there are several possible generalizations of Hilbert curves to higher dimensions.


3D Hilbert Curve | Curves and 3d
src: i.pinimg.com


Representation as Lindenmayer system

The Hilbert Curve can be expressed by a rewrite system (L-system).

Alphabet : A, B
Constants : F + -
Axiom : A
Production rules:
A -> - B F + A F A + F B -
B -> + A F - B F B - F A +

Here, "F" means "draw forward", "-" means "turn left 90°", "+" means "turn right 90°" (see turtle graphics), and "A" and "B" are ignored during drawing.


Space-Filling Curves (2 of 4: Hilbert Curve) - YouTube
src: i.ytimg.com


Other implementations

Graphics Gems II discusses Hilbert curve coherency, and provides implementation.


Hilbert Curve (Hand-Drawn) | Patterns | Pinterest | Curves, Hand ...
src: i.pinimg.com


See also

  • Hilbert curve scheduling
  • Hilbert R-tree
  • Sierpi?ski curve
  • Moore curve
  • Murray polygon
  • List of fractals by Hausdorff dimension

Developing Hilbert curve - YouTube
src: i.ytimg.com


Notes


Hilbert Cube In Blender by IamZandar on DeviantArt
src: orig00.deviantart.net


Further reading

  • Warren Jr., Henry S. (2013). Hacker's Delight (2 ed.). Addison Wesley - Pearson Education, Inc. ISBN 978-0-321-84268-8. 

Z-order curve Space-filling curve Hilbert curve - level png ...
src: banner.kisspng.com


External links

  • Dynamic Hilbert curve with JSXGraph
  • Three.js WebGL 3D Hilbert curve demo
  • XKCD cartoon using the locality properties of the Hilbert curve to create a "map of the internet"
  • Gcode generator for Hilbert curve
  • Iterative algorithm for drawing Hilbert curve in JavaScript

Source of article : Wikipedia