You are on page 1of 58

Space-Filling

Curves

An Introduction

Presented by Levi Valgaerts

JASS 2005 Saint Petersburg

Contents
1. Introductory section
2. Types of space-filling curves
1.
2.
3.
4.

The Hilbert space-filling curve


The Peano space-filling curve
The Sierpinski space-filling curve
The Lebesgue space-filling curve

3. Application of space-filling curves

JASS 2005 Saint Petersburg

Contents
1. Introductory section
2. Types of space-filling curves
1.
2.
3.
4.

The Hilbert space-filling curve


The Peano space-filling curve
The Sierpinski space-filling curve
The Lebesgue space-filling curve

3. Application of space-filling curves

JASS 2005 Saint Petersburg

Basic concepts from set theory: surjective,


injective, bijective mapping
1.

Surjective map from A onto B:

f ( A) B
with

f ( A) f ( x) Ran f | x A Dom f
the image of A under the function f
JASS 2005 Saint Petersburg

Basic concepts from set theory: surjective,


injective, bijective mapping
2.

Injective map from A into B:

x1 x2 f ( x1 ) f ( x2 )
3.

Bijective map from A onto B:

f is injective and surjective

JASS 2005 Saint Petersburg

Basic notations
n

Subsets of

Binary notation:

I 0,1 ,

0,1

02 b1b2b3... b1 / 2 b2 / 22 b3 / 23 ..., bj 0 or 1
Ternary notation:

03 t1t2t3... t1 / 3 t2 / 32 t3 / 33 ..., t j 0,1 or 2


Quaternary notation:

04 q1q2q3... q1 / 4 q2 / 42 q3 / 43 ..., q j 0,1, 2 or 3

JASS 2005 Saint Petersburg

Basic notations (remarks)

Periods

02 b1b2b3...bn 02 b1b2b3...bnbnbn ...

Finite binaries
02 b1b2b3 ...bn 02 b1b2b3 ...bn 000...
02 b1b2b3 ...bnb 02 b1b2b3 ...bn (b 1)1, b 1

e.g.

021 0202

because

JASS 2005 Saint Petersburg

1
1
n 2i 2n1

Curve definition
f : a, b
n is continuous, then f ([ a, b])
If
is called a curve. Without loss of generality we can assume the
domain to be I, f(0) and f(1) are the beginning and endpoint.
Notation:

f (t ) x ( x1 , x2 (, x3 )), t I

Parameter representation with component functions:


x1 (t )

x2 (t )
( x (t ))
3
JASS 2005 Saint Petersburg

Space-filling curve (SFC) definition


Curves that pass through every point of an n-dimensional region
with positive area (for n=2) or volume (for n=3), such as the unit
square in 2 or the unit cube in 3 , are called space-filling
curves.

Two main characteristics:


continuous
surjective
It can be shown that if f generates a space-filling curve, then it
can not be bijective.
JASS 2005 Saint Petersburg

Contents
1. Introductory section
2. Types of space-filling curves
1.
2.
3.
4.

The Hilbert space-filling curve


The Peano space-filling curve
The Sierpinski space-filling curve
The Lebesgue space-filling curve

3. Application of space-filling curves

JASS 2005 Saint Petersburg

Contents
1. Introductory section
2. Types of space-filling curves
1.
2.
3.
4.

The Hilbert space-filling curve


The Peano space-filling curve
The Sierpinski space-filling curve
The Lebesgue space-filling curve

3. Application of space-filling curves

JASS 2005 Saint Petersburg

The Hilbert curve: geometric generation

If I can be mapped continuously on , then after partitioning


I into four congruent subintervals and into four congruent
subsquares, each subinterval can be mapped continuously
onto one of the subsquares. This partitioning can be carried
out ad infinitum.
The subsquares must be arranged such that adjacent
subintervals are mapped onto adjacent subsquares.
Inclusion relationship: if an interval corresponds to a square,
then its subintervals must correspond to the subsquares of
that square.
This process defines a mapping f h ( I ) , called the Hilbert
space-filling curve.
JASS 2005 Saint Petersburg

The Hilbert curve: geometric generation


1/

2/

3/

4/

1
1/

16

2/

16

3/

16

4/

1,1

16

1,1

16/

16

0,0

16

0,0

1st iteration

2nd iteration

JASS 2005 Saint Petersburg

3rd iteration

The Hilbert curve: geometric generation

6th iteration
JASS 2005 Saint Petersburg

The Hilbert curve: geometric generation


The mapping f h : I
is surjective: with every sequence
of nested closed squares corresponds a sequence of nested closed
intervals that define a unique t0 I .
onto
The mapping f h : I

is continuous: in the nth iteration I


is partitioned in 22n subintervals, thus

t1 , t2 I t1 t2 1/ 22n then f h (t1 ) f h (t2 ) 5 / 2n


onto
The mapping f h : I

is nowhere differentiable.

JASS 2005 Saint Petersburg

The Hilbert curve: a complex representation [Sagan]

Establish a formula to calculate the exact coordinates of an


image point if
t k / 22 n , n 0,1, 2,3,..., k 0,1, 2,3,...22 n

Use complex representation z , and affine transformations to wich will be subjected recursively.
Give an orientation to each subsquare such that the exit point
of a subsquare coincides with the entry point of the next
subsquare.

JASS 2005 Saint Petersburg

The Hilbert curve: a complex representation

0th iteration

1
2

1st iteration

JASS 2005 Saint Petersburg

1
4

1
2

3
4

2nd iteration

The Hilbert curve: a complex representation


The four basic transformations (2 dimensional case):

1
1 i
h2 z z
2
2 2

x1 1 0
: h0
x2 2 1
x1 1 1
: h1
x2 2 0
x1 1 1
: h2
x2 2 0

1
i
h3 z zi 1
2
2

x1 1 0 1 x1 1 2 1
x1 1
: h3
H 3 h3

x2 2 1 0 x2 2 1 2
x2 2

1
h0 z zi
2
1
i
h1 z z
2
2

1 x1 1 0 1
x1 1
H 0 h0

0 x2 2 0 2 x2 2
0 x1 1 0 1 x1 1
H1 h1

1 x2 2 1 2 x2 2
0 x1 1 1 1
x1 1
H 2 h2

1 x2 2 1 2
x2 2

JASS 2005 Saint Petersburg

The Hilbert curve: a complex representation

Represent t I as t 04 q1q2 q3 ..., with q j 0,1, 2 or 3


f h (t ) hq1 , f h (t ) hq1 hq2 , ad infinitum:

f h (t ) lim hq1 hq2 hq3 ...hqn


n

For finite quaternaries (edges of subintervals in nth iteration):


f h (04 q1q2 q3 ... qn ) hq1 hq2 hq3 ...hqn h0 h0 h0 ...

0
f h (04 q1q2 q3 ... qn ) hq1 hq2 hq3 ...hqn
0
JASS 2005 Saint Petersburg

The Hilbert curve: a complex representation

continued...

n
0
1
hq1 hq2 hq3 ...hqn ... j
j 1 2
0

1
f h (04 q1q2 q3 ...) j
j 1 2

f h is cont .

H q0 H q1 H q2 H q3 ...H q j1 hq j

H q0 H q1 H q2 H q3 ...H q j1 hq j

Taking into account some properties of H q j :

1
f h (04 q1q2 q3 ...) j
j 1 2

e0 j e3 j
H 0 H 3 hq j ,

with ekj number of ks preceding q j (mod 2), k 0 or 3


JASS 2005 Saint Petersburg

The Hilbert curve: a complex representation

Further simplifications of the formula are possible...


An example:

0 5/ 8
f h (04 203) h2 h0 h3

0
3/
4

h2

(5 / 8,3/ 4)

h0
(0,0)

h3
JASS 2005 Saint Petersburg

Approximating polygons for the Hilbert curve


The polygonal line that runs through the points
f h (0), f h (1/ 22 n ), f h (2 / 22 n ), f h (3 / 22 n ),..., f h ((2 2 n 1) / 2 2 n ), f h (1),

is called the nth approximating polygon or a discrete space filling


curve.
Parametrization:

k
k 1
k 1
k
2n
pn : I : pn (t ) 2 (t 2 n ) f h ( 2 n ) 2 (t 2 n ) f h ( 2 n ),
2
2
2
2
for k / 22 n t (k 1) / 22 n , k 0,1, 2,3,...22 n 1
2n

{ pn } converges uniformly to the Hilbert curve


JASS 2005 Saint Petersburg

The Hilbert curve: representation through


grammars

Make use of four distinct templates to generate the discrete


Hilbert curve: H,A,B and C.
These templates will be translated to a first iteration of the
curve according to a fixed scheme.

JASS 2005 Saint Petersburg

The Hilbert curve: representation through


grammars

The resulting rules and transitions can be used to implement


the recursive construction of the discrete Hilbert curve.

JASS 2005 Saint Petersburg

3 dimensional SFCs

JASS 2005 Saint Petersburg

Contents
1. Introductory section
2. Types of space-filling curves
1.
2.
3.
4.

The Hilbert space-filling curve


The Peano space-filling curve
The Sierpinski space-filling curve
The Lebesgue space-filling curve

3. Application of space-filling curves

JASS 2005 Saint Petersburg

Contents
1. Introductory section
2. Types of space-filling curves
1.
2.
3.
4.

The Hilbert space-filling curve


The Peano space-filling curve
The Sierpinski space-filling curve
The Lebesgue space-filling curve

3. Application of space-filling curves

JASS 2005 Saint Petersburg

The Peano curve: definition

fp : I

with

03 t1 (k t2 t3 )(k t2 t4 t5 )...
f p (03 t1t2t3t4 ...)
0 (k t1 t )(k t1 t3 t )...
2
4
3

with kt j 2 t j (t j 0,1, 2) and k is the th it. of k


is surjective and continuous on I, and represents a SFC.

More interesting: geometric generation according to Hilbert

JASS 2005 Saint Petersburg

The Peano curve: geometric generation


From the defining formula we can derive:

030 23 4 ...
f p (0301t3t4t5 ...)

031 2 3 4 ...

030 234 ...


f p (0300t3t4t5 ...)

030 2 3 4 ...

1
3

3
2
3

1 2 fp 1 1 2
t ,
0, ,
9 9
3 3 3

1 fp 1 1
t 0,
0, 0,
9

3 3

...

JASS 2005 Saint Petersburg

1
3

2
3

The Peano curve: geometric generation

1st iteration

2nd iteration

JASS 2005 Saint Petersburg

3rd iteration

The Peano curve: a complex representation

Define orientation of the subsquares:

1
1
1 i
Define similarity transforms: p0 z z, p1 z z ,...
3
3
3 3

x1 1 x1 1
with p j Pj p j , j 0,1,...8
x2 3 x2 3
JASS 2005 Saint Petersburg

The Peano curve: a complex representation

Use ternary representation of t I :


03 t1t2 ...t2 n 2t2 n ... 09 (3t1 t2 )(3t3 t4 )...(3t2 n 1 t2 n )...

f p (t ) lim p3t1 t2 p3t3 t4 ... p3t2 n1 t2 n


n

Continue as with Hilberts curve...

we get the same result as in Peanos definition

JASS 2005 Saint Petersburg

Approximating polygons for the Peano curve

JASS 2005 Saint Petersburg

The Peano curve: representation through


grammars

JASS 2005 Saint Petersburg

Contents
1. Introductory section
2. Types of space-filling curves
1.
2.
3.
4.

The Hilbert space-filling curve


The Peano space-filling curve
The Sierpinski space-filling curve
The Lebesgue space-filling curve

3. Application of space-filling curves

JASS 2005 Saint Petersburg

Contents
1. Introductory section
2. Types of space-filling curves
1.
2.
3.
4.

The Hilbert space-filling curve


The Peano space-filling curve
The Sierpinski space-filling curve
The Lebesgue space-filling curve

3. Application of space-filling curves

JASS 2005 Saint Petersburg

The Sierpinski curve: generation


Originaly defined as a map f s from I onto
2
1,1 , but it can be considered as a map
from I onto a right isosceles triangle .

JASS 2005 Saint Petersburg

The Sierpinski curve: generation

Partition I into 2 n congruent subintervals and into


2 n congruent subtriangles.
(1,1)

(0, 0)

(2, 0)

n=1

n=0

n=2

In deriving an algabraic representation it is easier to divide I


into 22n subintervals, thus using quaternaries:

1
S q0 S q1 S q2 ...S q j1 sq j
j
j 1 2

f s (04 q1q2 q3 ...)

JASS 2005 Saint Petersburg

The Sierpinski curve: generation


with similarity transforms:
S0 z z / 2
S1 z zi / 2 1
S 2 z zi / 2 1 i
S3 z z / 2 1

x1 1 1 0 x1 1 0 1 x1 1
: S0
S0 s0
x2 2 0 1 x2 2 0 2 x2 2
x1 1 0 1 x1 1 2 1 x1 1
: S1
S1 s1
x2 2 1 0 x2 2 0 2 x2 2
x1 1 0 1 x1 1 2 1 x1 1
: S2
S2 s2
x2 2 1 0 x2 2 2 2 x2 2
x1 1 1 0 x1 1 2 1 x1 1
: S3
S3 s3
x2 2 0 1 x2 2 0 2 x2 2

JASS 2005 Saint Petersburg

The Sierpinski curve: generation

Taking into account some properties of Sq j :

f s (04 q1q2 q3 ...) j ( 1) j S j sq j


j 1 2
with j number of 2s preceding q j (mod 2)
and j number of 1s and 2s preceding q j (mod 4)

JASS 2005 Saint Petersburg

The Sierpinski curve: approximating polygons

(1,1)

(0, 0)

(2, 0)

n=0

n=1

n=2

JASS 2005 Saint Petersburg

n=3

Contents
1. Introductory section
2. Types of space-filling curves
1.
2.
3.
4.

The Hilbert space-filling curve


The Peano space-filling curve
The Sierpinski space-filling curve
The Lebesgue space-filling curve

3. Application of space-filling curves

JASS 2005 Saint Petersburg

Contents
1. Introductory section
2. Types of space-filling curves
1.
2.
3.
4.

The Hilbert space-filling curve


The Peano space-filling curve
The Sierpinski space-filling curve
The Lebesgue space-filling curve

3. Application of space-filling curves

JASS 2005 Saint Petersburg

The Lebesgue curve: introduction


Introduction of a remarkable subset of I, the Cantor Set
{03 (2t1 )(2t2 )(2t3 )... | t j 0 or 1} ,of wich all elements can be
represented by

2t1 2t2 2t3 2t4


2 3 4 ..., with t j 0 or 1
3 3
3
3

may be constructed by recursively removing the middle third of


every closed subinterval beginning with I. The numbers that are
generated in this proces do not contain a 1 in their ternary
representation.

JASS 2005 Saint Petersburg

The Lebesgue curve: introduction

1.

1 2
0, ,1
3 3

2.

1 2 1 2 7 8
0, , , ,1
9 9 3 3 9 9

3.

...

1
27

2 1
27 9

2
9

7
27

8
27

1
3

2
3

JASS 2005 Saint Petersburg

7
9

8
9

The Lebesgue curve: definition


We define the continuous and surjective mapping f :

02 t1t3t5 ...
f (03 (2t1 )(2t2 )(2t3 )...)

02 t2t4t6 ...
and extend f continuously into I by linear interpolation in every
interval that is removed in the generation of :
1
fl (t )
f (an )(bn t ) f (bn )(t an ) , an t bn
bn an

with an , bn removed in the nth iteration step. Further we say


fl (t ) f (t ) on . Than f l defines the Lebesgue space-filling curve.
JASS 2005 Saint Petersburg

The Lebesgue curve: generation and approximating polygons

1st iteration

2nd iteration

JASS 2005 Saint Petersburg

4th iteration

Contents
1. Introductory section
2. Types of space-filling curves
1.
2.
3.
4.

The Hilbert space-filling curve


The Peano space-filling curve
The Sierpinski space-filling curve
The Lebesgue space-filling curve

3. Application of space-filling curves

JASS 2005 Saint Petersburg

Contents
1. Introductory section
2. Types of space-filling curves
1.
2.
3.
4.

The Hilbert space-filling curve


The Peano space-filling curve
The Sierpinski space-filling curve
The Lebesgue space-filling curve

3. Application of space-filling curves

JASS 2005 Saint Petersburg

Application of space-filling curves


2 dimensional SFCs give a recipe for going through a set of 2
dimensional data that are arranged on a grid:

going through pixels that make up an image being scanned


matrix operations in linear algebra
going through / representing a 2D computational grid
...

Favorable property: better exploitation of the 2D locality due to


the recursive nature / self-similarity.

JASS 2005 Saint Petersburg

Application of space-filling curves


1.

Representation of computational grids (1)

Acceptable computational complexity is required in implementing computational grids. Especially for adaptively refined grids
the manipulation part cannot be too expensive choice of appropriate data structures is important.
Often applied: space trees of which the leaves correspond to the
grid cells that are enumerated by a discrete SFC. For adaptively
refined grids we use different iterates depending on the level of
refinement.
JASS 2005 Saint Petersburg

Application of space-filling curves


1.

Representation of computational grids (2)

JASS 2005 Saint Petersburg

Application of space-filling curves


2.

Implementation with respect to cache-efficiency (1)

Data access of hierarchically stored data can be slow. By using


SFC we try to process the data linearly in a way that reduces data
access time and cache misses.
Build a fixed number of stacks to avoid random access in the
memory, such that data (information in a grid point) needed in
the operation sequence is always on top. The corresponding
processing order of the grid cells is defined by a SFC.

JASS 2005 Saint Petersburg

Application of space-filling curves


2.

Implementation with respect to cache-efficiency (2)

Use of two stacks with a Peano curve on a 2D regular grid

JASS 2005 Saint Petersburg

Application of space-filling curves


2.

Implementation with respect to cache-efficiency (3)

Consequences:

Memory behaviour becomes deterministic and processing order


is easily inverted.
The discrete operator has to be decomposed per cell such that
the accumulated effect corresponds to the execution of the whole
operator after one run over all cells.

JASS 2005 Saint Petersburg

Application of space-filling curves


3.

Grid partitioning and parallellisation (1)

For running a PDE solver on a parallel computer we need to


partition the data and map each block to a processor such that data
transfer between the processors is as small as possible.
Multi-dimensional data can be mapped to a one-dimensional
sequence using the inverse of a discrete SFC mapping. The points
on I that are the images of nodes in space can be grouped together
and mapped on a processor. We use seperators to form partitions
that contain the same number of nodes for perfect load balance.
JASS 2005 Saint Petersburg

Application of space-filling curves


3.

Grid partitioning and parallellisation (2)

Set of points: S {xi | xi }

{xi | s j f 1 ( xi ) s j 1}

S
j

Ij
j

where I j of equal workload, gives small seperators f ( I j ) \


, in fact quasi-optimal seperator sizes where other partition
methods fail.
JASS 2005 Saint Petersburg

List of references
[1] Hans Sagan, Space-Filling Curves, Springer-Verlag, 1994.
[2] Michael Bader, Raumfllende Kurven, Institut fr Informatik
der Technischen Universitt Mnchen, 2004.
[3] F. Gnther, M. Mehl, M. Pgl, C. Zenger, A cache-aware
algorithm for PDEs on hierarchical data structures based on
space-filling curves.
[4] Gerhard Zumbusch, Adaptive Parallel Multilevel Methods for
Partial Differential Equations.
[5] R. Dafner, D. Cohen-Or, Y. Matias, Context-based Space
Filling Curves, 2000.
[6] www.wikipedia.org
JASS 2005 Saint Petersburg

You might also like