CG 5
CG 5
CG 5
Aim : Write C++ program to generate Hilbert curve using concept of fractals.
Software Requirements :
• 64-bit Open source Linux
Hardware Requirement :
• C2D, 2GB RAM, 500 GB HDD.
Objectives :
To understand and implement Hilbert curve using fractals.
Outcomes :
Students are able to understand mathematics behind generation of Hilbert curve using fractals.
Theory :
The Hilbert curve
The Hilbert curve is a space filling curve that visits every point in a square grid with a size of 2×2, 4×4,
8×8, 16×16, or any other power of 2. It was first described by David Hilbert in 1892. Applications of the
Hilbert curve are in image processing: especially image compression and dithering. It has advantages in
those operations where the coherence between neighbouring pixels is important. The Hilbert curve is
also a special version of a quadtree; any image processing function that benefits from the use of
quadtrees may also use a Hilbert curve.
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 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 colour of each pixel, and the Hilbert curve is
sometimes used because it keeps nearby IP addresses close to each other in the picture
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 called the Hilbert space-filling curve.
Cups and joins
The basic elements of the Hilbert curves are what I call "cups" (a square with one open side) and "joins"
(a vector that joins two cups). The "open" side of a cup can be top, bottom, left or right. In addition,
every cup has two end-points, and each of these can be the "entry" point or the "exit" point. So, there
are eight possible varieties of cups. In practice, a Hilbert curve uses only four types of cups. In a similar
vein, a join has a direction: up, down, left or right.
A first order Hilbert curve is just a single cup (see the figure on the left). fills a 2×2 space. The second
order Hilbert curve replaces that cup by four (smaller) cups, which are linked together by three joins
(see the figure on the right; the link between a cup and a join has been marked with a fat dot in the
figure). Every next order repeats the process or replacing each cup by four smaller cups and three joins.
Cup subdivision rules
The function presented below (in the "C" language) computes the Hilbert curve. Note that the curve is
symmetrical around the vertical axis. It would therefore be sufficient to draw half of the Hilbert curve.
Snowflake curve :
Snowflake curve is drawn using koch curve iterations. In koch curve, we just have a single line in the
starting iteration and in snowflake curve, we have an equilateral triangle. The Koch snowflake can be
built up iteratively, in a sequence of stages. The first stage is an equilateral triangle, and each successive
stage is formed by adding outward bends to each side of the previous stage, making smaller equilateral
triangles. The areas enclosed by the successive stages in the construction of the snowflake converge
to times the area of the original triangle, while the perimeters of the
successive stages increase without bound. Consequently, the snowflake encloses a finite area, but has
an infinite parameters.
Construction of Snowflake :
The Koch snowflake can be constructed by starting with an equilateral triangle , then recursively
altering each line segment as follows:
If the original equilateral triangle has sides of length the length of each side of the
an inverse power of three multiple of the original length. The perimeter of the snowflake after
iterations is :
The Koch curve has an infinite length, because the total length of the curve increases by a factor
of with each iteration. Each iteration creates four times as many line segments as in the
previous iteration, with the length of each one being the length of the segments in
the previous stage. Hence, the length of the curve after iterations will be
Algorithm :
Flowchart :
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: