Year & Branch: S.E.
Computer Engineering
Subject Name: Computer Graphics (210251)
  Unit-6: Curves and Fractals
               Fractals
                Mr. Bhushan S. Gholap      1
               Hilbert’s Curve..
• Hilbert Curves are named after the German mathematician
  David Hilbert. They were first described in 1891.
• It is also called as Peano curve. (as a variant of the space-
  filling Peano curves discovered by Giuseppe Peano in 1890)
• A Hilbert curve is a continuous space-filling curve. They
  are also fractal and are self-similar; If you zoom in and look
  closely at a section of a higher-order curve, the pattern you
  see looks just the same as itself.
                          Mr. Bhushan S. Gholap              2
               Hilbert’s Curve..
• The curve begins with initial square. The generation of
  curve requires successive approximations.
• Cups and Joins: The basic elements of the Hilbert curves
  are "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 a similar vein, a join has a
  direction: up, down, left or right.
                          Mr. Bhushan S. Gholap            3
              Hilbert’s Curve..
• In the first approximation, we are dividing the square into
  four quadrants and then drawing the curve which connects
  the center points of each quadrant.
                        Mr. Bhushan S. Gholap             4
              Hilbert’s Curve..
• The second approximation will be to further subdivide each
  of the four quadrants and draw the curve which connects the
  center points of each these finer subdivisions before moving
  the next major quadrant.
                        Mr. Bhushan S. Gholap              5
               Hilbert’s Curve..
• The third approximation again subdivides each quadrant
  and process continues.
• Hilbert curves, first to third order as shown in figure.
                           Mr. Bhushan S. Gholap             6
                Hilbert’s Curve..
• We will come to know that, the curve is not getting
  overlap at any point.
• There is no limit to this subdivision. The curve fills
  the square.
• Ideally, the length of curve is infinite. With each
  subdivision the length increases by factor 4.
• Topological Dimension (Dt) must be equal to 1.
                      Mr. Bhushan S. Gholap          7
                 Hilbert’s Curve..
• At each subdivision the scale (S) changes by 2 i.e. at every
  approximation we are dividing plane into four quadrants.
• But the length (N) of the curve changes by 4, at each
  subdivision. So we need 4 scaled curves to form original
  curve.
• i.e. N = SDf
       4 = 2Df
       Df = 2
     (Df - Fractal Dimension)
                         Mr. Bhushan S. Gholap               8
              Hilbert’s Curve..
• Hilbert curve has,
   – Topological Dimension (Dt) = 1
   – Fractal Dimension(Df) = 2
• So, Hilbert curve is a line only, but it is so folded
  that it looks likes a 2D object.
                       Mr. Bhushan S. Gholap        9
           University Questions
1. Explain Hilbert curve with example.
2. What is fractal ? Explain Hilbert curve in detail.
3. Explain Hilbert curve and its application in details.
                         Mr. Bhushan S. Gholap             10
Assignment No. 7: Write C++/Java program to generate
                  Hilbert curve using concept of fractals.
   #include<iostream>
   #include<stdio.h>
   #include<graphics.h>
   #include<math.h>
   #include<stdlib.h>
   using namespace std;
   void move(int j, int h, int &x, int &y) // Move function
   {
     if(j==1)
        y = y-h;
     elseif(j==2)
        x = x+h;
     else if(j==3)
        y = y+h;
     else if(j==4)
         x = x-h;
       lineto(x,y); //Draws a line from current position to the point(x,y).
   }
                                               Mr. Bhushan S. Gholap          11
void hilbert(int r,int d,int l ,int u,int i,int h,int &x,int &y)    int main()
{//Hillbert Curve Function                                          {
    if(i>0)                                                             int n,x1,y1;
    {                                                                   int x0=50,y0=150,x,y,h=10,r=2,d=3,l=4,u=1;
        i--;
                                                                         cout<<"Give the value of n"; //Accept value for n
        hilbert(d,r,u,l,i,h,x,y);                                        cin>>n;
        move(r,h,x,y);                                                   x=x0;
        hilbert(r,d,l,u,i,h,x,y);                                        y=y0;
        move(d,h,x,y);
                                                                         int driver=DETECT,mode=0;
        hilbert(r,d,l,u,i,h,x,y);
                                                                         initgraph(&driver,&mode,NULL);
        move(l,h,x,y);
        hilbert(u,l,d,r,i,h,x,y);                                         moveto(x,y);
    }                                                                     hilbert(r,d,l,u,n,h,x,y);
}
                                                                          delay(100000);
                                                                          closegraph();
                                                                          return 0;
                                                                    }
                                                         Mr. Bhushan S. Gholap                                           12
• To be continue…
     Mr. Bhushan S. Gholap   13