It is simple to define a mapping from the unit interval into the unit square
. Georg Cantor found a one-to-one map from
onto
, showing that the one-dimensional interval and the two-dimensional square have the same cardinality. Cantor’s map was not continuous, but Giuseppe Peano found a continuous surjection from
onto
, that is, a curve that fills the entire unit square. Shortly afterwards, David Hilbert found an even simpler space-filling curve, which we discussed in Part I of this post.
The Hilbert curve is constructed as the limit of a sequence of functions from the unit interval
to the unit square
. The approximating curves give an impression of the Hilbert curve, which we may denote by
or more simply as
. However, we did not explain how to calculate the coordinates of the image point
for an arbitrary
. It was also not obvious that the curve
really passes through every point in the unit square.
An Explicit Expression
Hilbert gave a geometrical argument that the function is surjective. However, an explicit expression for
was not found for 100 years after Hilbert’s paper appeared. In 1991, Hans Sagan obtained an expression that enables the numerical value of the image of any point to be calculated. For dyadic arguments
the expression is a finite sum, yielding an exact answer. For general arguments, the value is given by an infinite sum. The expression is given in Sagan’s book (Sagan, 1994). This book is also an excellent source for more general space-filling curves, covering both the historical development of the subject and the technical details required to construct such curves.
The function
It is convenient to work with quaternary expansions of numbers in the unit interval:
As usual, we write . Sagan derives the following expression for the image of the point
where is the number of
‘s in
preceding
(
),
is the number of
‘s preceding
(
),
and
is the signum function of
.
Following Sagan, let us consider a simple example, , which has the quaternary expansion
. We easily calculate the following:
Plugging these values into (1) we get
So maps to the point
.
We denote the unit square by , the first partition into quadrants as
and so on. Thus, the quadrant
is partitioned into
. We number the quadrants according to the order in which they come after the reflections required to ensure continuity. Then the point
is at the north-east corner of the element
.
Hilbert Curves in Other Shapes
A continuous function of a continuous function is continuous. Given the space-filling curve on
, we can map
continuously onto another shape and obtain a space-filling curve on that. The shape does not have to be convex, or even simply connected. In the Figure below, we show (approximations to) space-filling curves on the unit square, unit disk, cardioid and annulus.
Some Additional Remarks
The Hilbert curve is not just dense in , but actually passes through every point in the unit square. This is amazing. For all the approximating functions
, at least one of the coordinates of each point is rational. Therefore, a point such as
cannot be on a curve
for any
. However, since the repeatedly partitioned squares become smaller with each iteration, we can approximate any point
in
by a sequence of squares. Corresponding to these are a nested sequence of diminishing intervals in
. Thanks to continuity, the limiting point
of this sequence is mapped by the function
to the chosen point:
.
The construction of ensures its continuity. However, the Hilbert curve is nowhere differentiable. Since Netto proved that one-to-one functions from
to
cannot be continuous, the Hilbert curve cannot be injective: it maps
onto the entirety of
, but there are many points in
that have more than one pre-image. The central point
is one of these.
We can approach the central point in several ways. We can jump directly to , which is what happens for the quaternary expansion of
, which is
. We can also get there by choosing the quadrant
and then the north-east quadrant at each subsequent scale. This happens for the number
, which corresponds to
. Finally, we can get to the centre by choosing
and then the north-west quadrant at all smaller scales, which arises from the number
or
. Thus, all the points
in the unit interval
map to the same point in
.
“But yet I’ll make assurance double sure”
Let us confirm that (1) gives the correct results. For , the expansion reduces to a single term
.
For we have
and the expansion is
For , we get
and the expansion is
Thus, all three values of map to the central point of the unit square.
Some beautiful animations of the Hilbert curve are given on Brian Hayes’ website. See also his book (Hayes, 2017).
Sources
Hayes, Brian, 2017: Foolproof, and Other Mathematical Meditations. MIT Press. 248pp. ISBN: 978-0-2620-3686-3.
Sagan, Hans, 1994: Space-filling curves. Springer-Verlag, New York. 193pp. ISBN: 0-387-94265-3.