Hilbert curve
   HOME

TheInfoList



OR:

The Hilbert curve (also known as the Hilbert space-filling curve) is a
continuous Continuity or continuous may refer to: Mathematics * Continuity (mathematics), the opposing concept to discreteness; common examples include ** Continuous probability distribution or random variable in probability and statistics ** Continuous g ...
fractal In mathematics, a fractal is a geometric shape containing detailed structure at arbitrarily small scales, usually having a fractal dimension strictly exceeding the topological dimension. Many fractals appear similar at various scales, as ill ...
space-filling curve In mathematical analysis, a space-filling curve is a curve whose range contains the entire 2-dimensional unit square (or more generally an ''n''-dimensional unit hypercube). Because Giuseppe Peano (1858–1932) was the first to discover one, ...
first described by the German mathematician
David Hilbert David Hilbert (; ; 23 January 1862 – 14 February 1943) was a German mathematician, one of the most influential mathematicians of the 19th and early 20th centuries. Hilbert discovered and developed a broad range of fundamental ideas in many ...
in 1891, as a variant of the space-filling
Peano curve In geometry, the Peano curve is the first example of a space-filling curve to be discovered, by Giuseppe Peano in 1890. Peano's curve is a surjective, continuous function from the unit interval onto the unit square, however it is not in ...
s discovered by
Giuseppe Peano Giuseppe Peano (; ; 27 August 1858 – 20 April 1932) was an Italian mathematician and glottologist. The author of over 200 books and papers, he was a founder of mathematical logic and set theory, to which he contributed much notation. The sta ...
in 1890. Because it is space-filling, its
Hausdorff dimension In mathematics, Hausdorff dimension is a measure of ''roughness'', or more specifically, fractal dimension, that was first introduced in 1918 by mathematician Felix Hausdorff. For instance, the Hausdorff dimension of a single point is zero, of ...
is 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). The Hilbert curve is constructed as a limit of
piecewise linear curve In geometry, a polygonal chain is a connected series of line segments. More formally, a polygonal chain is a curve specified by a sequence of points (A_1, A_2, \dots, A_n) called its vertices. The curve itself consists of the line segments co ...
s. The length of the nth curve is \textstyle 2^n - , i.e., the length grows exponentially with n, even though each curve is contained in a square with area 1.


Images

File:Hilbert curve 1.svg, Hilbert curve, first order File:Hilbert curve 2.svg, Hilbert curves, first and second orders File:Hilbert curve 3.svg, Hilbert curves, first to third orders File:Hilbert curve production rules!.svg, Production rules File:Hilbert.png, Hilbert curve, construction color-coded File:Hilbert3d-step3.png, A 3-D Hilbert curve with color showing progression File:Courbe de Hilbert.jpg, Variant, first three iterations


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 preserves locality fairly well. This means that two data points which are close to each other in one-dimensional space are also close to each other after folding. The converse cannot always be true. Because of this locality property, the Hilbert curve is widely used in computer science. For example, the range of
IP address An Internet Protocol address (IP address) is a numerical label such as that is connected to a computer network that uses the Internet Protocol for communication.. Updated by . An IP address serves two main functions: network interface ident ...
es 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. In an algorithm called Riemersma dithering,
grayscale In digital photography, computer-generated imagery, and colorimetry, a grayscale image is one in which the value of each pixel is a single sample representing only an ''amount'' of light; that is, it carries only intensity information. Graysc ...
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 code The reflected binary code (RBC), also known as reflected binary (RB) or Gray code after Frank Gray, is an ordering of the binary numeral system such that two successive values differ in only one bit (binary digit). For example, the representa ...
s, 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 R-trees are tree data structures used for spatial access methods, i.e., for indexing multi-dimensional information such as geographical coordinates, rectangles or polygons. The R-tree was proposed by Antonin Guttman in 1984 and has found sig ...
indexes (see
Hilbert R-tree Hilbert R-tree, an R-tree variant, is an index for multidimensional objects such as lines, regions, 3-D objects, or high-dimensional feature-based parametric objects. It can be thought of as an extension to B+-tree for multidimensional objects. Th ...
). 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 in the lower-right corner. This is different from the animation shown above where the curve starts from upper left corner and terminates at upper right corner. //convert (x,y) to d int xy2d (int n, int x, int y) //convert d to (x,y) void d2xy(int n, int d, int *x, int *y) //rotate/flip a quadrant appropriately void rot(int n, int *x, int *y, int rx, int ry) These use the C conventions: the & symbol is a bitwise AND, the ^ symbol is a bitwise XOR, += is the addition/assignment operator (x += y is equivalent to x = x + y), and /= is the division/assignment operator. 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.


Representation as Lindenmayer system

The Hilbert Curve can be expressed by a
rewrite system In mathematics, computer science, and logic, rewriting covers a wide range of methods of replacing subterms of a formula with other terms. Such methods may be achieved by rewriting systems (also known as rewrite systems, rewrite engines, or reduc ...
(
L-system An L-system or Lindenmayer system is a parallel rewriting system and a type of formal grammar. An L-system consists of an alphabet of symbols that can be used to make strings, a collection of production rules that expand each symbol into som ...
). :Alphabet : A, B :Constants : F + − :Axiom : A :Production rules: :: A → +BF−AFA−FB+ :: B → −AF+BFB+FA− Here, "F" means "draw forward", "+" means "turn left 90°", "-" means "turn right 90°" (see
turtle graphics In computer graphics, turtle graphics are vector graphics using a relative cursor (the "turtle") upon a Cartesian plane (x and y axis). Turtle graphics is a key feature of the Logo programming language. Overview The turtle has three attribut ...
), and "A" and "B" are ignored during drawing.


Other implementations

Graphics Gems IIVoorhies, Douglas: Space-Filling Curves and a Measure of Coherence, pp. 26–30, Graphics Gems II. discusses Hilbert curve coherency, and provides implementation. The Hilbert Curve is commonly used among rendering images or videos. Common programs such as
Blender A blender (sometimes called a mixer or liquidiser in British English) is a kitchen and laboratory appliance used to mix, crush, purée or emulsify food and other substances. A stationary blender consists of a blender container with a rotating me ...
and
Cinema 4D Cinema 4D is a 3D software suite developed by the German company Maxon. Overview As of R21, only one version of Cinema 4D is available. It replaces all previous variants, including BodyPaint 3D, and includes all features of the past 'Studio' ...
use the Hilbert Curve to trace the objects, and render the scene.


See also

*
Hilbert curve scheduling In parallel processing, the Hilbert curve scheduling method turns a multidimensional task allocation problem into a one-dimensional space filling problem using Hilbert curves, assigning related tasks to locations with higher levels of proximity.''S ...
*
Hilbert R-tree Hilbert R-tree, an R-tree variant, is an index for multidimensional objects such as lines, regions, 3-D objects, or high-dimensional feature-based parametric objects. It can be thought of as an extension to B+-tree for multidimensional objects. Th ...
*
Locality of reference In computer science, locality of reference, also known as the principle of locality, is the tendency of a processor to access the same set of memory locations repetitively over a short period of time. There are two basic types of reference localit ...
* Locality-sensitive hashing *
Moore curve A Moore curve (after E. H. Moore) is a continuous fractal space-filling curve which is a variant of the Hilbert curve. Precisely, it is the loop version of the Hilbert curve, and it may be thought as the union of four copies of the Hilbert curves ...
*
Murray polygon In geometry, the Peano curve is the first example of a space-filling curve to be discovered, by Giuseppe Peano in 1890. Peano's curve is a surjective, continuous function from the unit interval onto the unit square, however it is not injective ...
* Sierpiński curve *
List of fractals by Hausdorff dimension According to Benoit Mandelbrot, "A fractal is by definition a set for which the Hausdorff-Besicovitch dimension strictly exceeds the topological dimension." Presented here is a list of fractals, ordered by increasing Hausdorff dimension, to illus ...


Notes


Further reading

* *


External links


Dynamic Hilbert curve with JSXGraph



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

Algorithm 781: generating Hilbert's space-filling curve by recursion (ACM Digital Library)
{{Fractals Fractal curves Articles containing video clips Articles with example C code