• Embed Doc
  • Readcast
  • Collections
  • CommentGo Back
Download
 
 Algorithm 781: Generating Hilbert’sSpace-Filling Curve by Recursion
GREG BREINHOLT and CHRISTOPH SCHIERZSwiss Federal Institute of Technology
 An efficient algorithm for the generation of Hilbert’s space-filling curve is given. Thealgorithm implements a recursive procedure that involves simple integer operations andquickly converges to the set of points that make the Hilbert curve. The algorithm is elegant,short, and considerably easier to implement than previous recursive and nonrecursivealgorithms and can be efficiently implemented in all programming languages that haveinteger operations and allow recursion. The fundamental Hilbert shape (a line joining the fourcorners of a square) is represented by two variables with values of either 0 or 1. This codingtechnique could be successfully applied to the generation of other regular space-filling curves,such as the Peano curve.Categories and Subject Descriptors: D.3.2 [
Programming Languages
]: Language Classifica-tions—
C
; I.3.3 [
Computer Graphics
]: Picture/Image Generation—
line and curve generation
General Terms: Algorithms Additional Key Words and Phrases: Recursion
1. INTRODUCTION
 Although it was Peano [1890] that produced the first space-filling curves, itwas Hilbert [1891] who first popularized their existence and gave aninsight into their generation. Space-filling curves are commonly used toreduce a multidimensional problem to a one-dimensional problem; thecurve is essentially a linear transversal of the discrete multidimensionalspace. Hilbert curves belong to the class of 
FASS
curves; an acronym forspace-
illing, self-
a
voiding,
s
imple, and self-
s
imilar [Prusinkiewicz andLindenmayer 1990]. FASS curves can be thought of as finite, self-avoidingapproximations of curves that pass through all points of a square. TheHilbert curve is a particular form of the FASS curve that scans a
2
m
2
m
array of points while never maintaining the same direction for more
 Authors’ address: Institute for Hygiene and Applied Physiology, Swiss Federal Institute of Technology, Zurich, CH-8092, Switzerland; email: breinholt@computer.org.Permission to make digital/hard copy of part or all of this work for personal or classroom useis granted without fee provided that the copies are not made or distributed for profit orcommercial advantage, the copyright notice, the title of the publication, and its date appear,and notice is given that copying is by permission of the ACM, Inc. To copy otherwise, torepublish, to post on servers, or to redistribute to lists, requires prior specific permissionand/or a fee. © 1998 ACM 0098-3500/98/0600–0184 $5.00
 ACM Transactions on Mathematical Software, Vol. 24, No. 2, June 1998, Pages 184–189.
 
than three consecutive points. Figure 1 shows an example of a Hilbertcurve.Different methods of curve generation have been suggested: a byte-oriented technique [Butz 1971], an arithmetization of the curve [Sagan1992], L-system formalization with turtle interpretation [Prusinkiewicz etal. 1991], and fractal curve generation [Ohno and Ohyama 1991; Peitgen etal. 1992]. A simple algorithm for the generation of the nodal points of theHilbert curve has also been derived by Sagan [1994], though when thesepoints are linked they produce only approximating polygons that are not a“true” representation of the Hilbert curve.Though space-filling curves were discovered over a century ago their usehas been sporadic but varied. Interesting examples of their use have beenin mathematics and data structures [Butz 1968; 1969; Gotsman andLindenbaum 1994; Asano et al. 1995], traveling salesman problems [Gaoand Steele 1994; Norman and Moscato 1995], image manipulation andanalysis [Stevens et al. 1983; Kamata et al. 1995; Agranov and Gotsman1995; Lamarque and Robert 1996; Giordana and Pieczynski 1997], digitalhalftoning [Witten and Neal 1982; Velho and Gomes 1991; Zhang andWebber 1993], pattern and texture analysis [Abend et al. 1965; Lee andHsueh 1994], cryptology [Matias and Shamir 1987; Bertilsson et al. 1989],and data compression [Bially 1969; Moghaddam et al. 1991].Most of the techniques for curve generation are interpretations of Hil-bert’s original suggestion to continually divide a plane into four parts, eachof these parts into four parts, and so on, calculating the necessary plottingpoints as the division proceeds. This continual dividing of the planecontinues until the required curve resolution is obtained, i.e., in a typicalrecursive procedure. The exact method to determine the points was notgiven by Hilbert (who worked before the invention of computers), and thishas lead to the many different programming code solutions to the problem[Goldschlager 1981; Cole 1983; Willen and Wyvill 1983].This article presents a simple computer-based algorithm that can quicklyand efficiently generate the points of the Hilbert curve using the simplestrecursive technique.
Fig. 1. Hilbert curve filling an area of 
32
32
points.
 Algorithm 781: Generating Hilbert’s Space-Filling Curve
185
 ACM Transactions on Mathematical Software, Vol. 24, No. 2, June 1998.
 
2. IMPLEMENTATION
The Hilbert curve can be deconstructed into a set of unit shapes (Figure 2),the relative position and rotation of each defined by its sequential positionin the curve generation. As the resolution of the curve increases, more unitshapes are required for its description, but the principle remains true toHilbert’s original proposition of dividing each part into smaller parts. As the curve progresses, the rotation of each unit shape follows a patternthat must be efficiently coded to describe both the rotation of the unitshape and its start and end points, so that the points of the curve can beplotted in the correct position and the correct order. The scheme chosencodes the rotation of each unit shape into two variables
i1
and
i2
, whichrepresent the starting point and end point respectively (Figure 3). Variable
i1
is given the value 0 when the starting point is in the lowerleft corner of the unit shape, and the value 1 when the starting point is inthe upper right corner. Variable
i2
is given the value 0 when the end pointof the unit shape is in the lower right corner, and the value 1 when the endpoint is in the upper left corner. Figure 4 illustrates this coding systemwhen applied to four of the possible orientations of the unit shape used toconstruct the curve.The method is implemented in a recursive procedure that modifies itscalling parameters as it converges to the set of points on the curve. Forexample, to generate a curve that fills a
64
64
point area, the followingis the first call:
Hilbert
0,0,64,0,0
.
3. IMPLEMENTATION RESULTS
The procedure works by recursively calling itself, modifying its parameterswith each call, until it reaches the smallest unit shape for the next sectionof the curve to be plotted. This occurs by repeatedly halving the parameter
lg
(representing the side length of the unit shape) until a unit value isachieved, and then the next four points on the curve are plotted.The number of calls to the procedure can be easily calculated:
 Number Calls
2
13
2
1
Fig. 2. Deconstructed unit shapes for different curve resolutions. The circles represent thestart points.
186
G. Breinholt and C. Schierz
 ACM Transactions on Mathematical Software, Vol. 24, No. 2, June 1998.
of 00

Leave a Comment

You must be to leave a comment.
Submit
Characters: ...
You must be to leave a comment.
Submit
Characters: ...