next up previous
Next: Inside the turtle's shell Up: A turtle in a Previous: Cantor sets


The Sierpinski gasket

Another very commonly encountered fractal is the Sierpinski gasket, which can be described as follows:

We start with an equilateral triangle $ \Cal{S}_0$, and replace it by three equilateral triangles with a base half the size of the original, stacked so the original perimiter is kept, but leaving a hole in the center. We then replace each of those triangles by three more triangles, to obtain $ \Cal{S}_2$ as nine triangles, each with a base of length 1/4. Continuing in this fashion infinitely many times yields the Sierpinski gasket $ \Cal{S}$. The sets $ \Cal{S}_0$ through $ \Cal{S}_6$ are shown below.


\begin{mfigure}\centerline{\psfig{figure=turtle501.eps,width=.95\hsize}}\end{mfigure}

It is easy to see that $ \boxdim$$ \Cal{S}$ is ln 3/ln 2, or about 1.58. You should try to confirm this fact for yourself. The self-similarity of the Sierpinski gasket should help this calculation considerably.


How might we coerce our turtle into making a Sierpinski gasket? While the procedure is simple enough to describe, explicitly writing it down in symbols requires a bit of thought. Give it a try before continuing.


One way to accomplish this5.18involves taking a slightly different viewpoint. Rather than making the gasket by replacing triangles with smaller triangles, we construct a fractal ``curve'' that traverses the base and the perimeters of the ``holes''. This traces out the same sets $ \Cal{S}_n$, except for two segments which we can easily add later.

We view S0 as the straight horizontal segment F, along with two other segments which are not horizontal. To emphasize the difference between the horizontal and the non-horizontal segments, we will traverse the non-horizontal segments backwards, and use the command B. Thus, our first triangle is S0 = FRBLLB.

Now, to obtain S1 from S0, we replace the horizontal segment F by two smaller ones with an inverted triangle between them. As with S0, we use F to denote the horizontal parts and B for the non-horizontal portions. Thus, we apply the transformation F $ \mapsto$ SF RBLFLBR FG. This gives us S1 from S0 as the command ``SF RBLFLBR FG RBLLB''. If we replace all three Fs in S1 using this transformation, we will obtain S2.

Before we try to describe any of the Sn recursively, note that in this description, each one really consists of two pieces: there is the complicated, recursive portion which describes most of the gasket, and then there is the final RBLLB which makes the outer ``hat'' (see figure 4). Let's call the commands to produce this first part sn and call commands for the hat h, that is, Sn = sn h. Then we can describe Sn as follows

Sn = sn h        sn = $\displaystyle \left\{\vphantom{ \begin{array}{ll}
\text{S}s_{n-1}\text{RBL}s_{...
...{G} & \text{if}  n>0 \\
\text{F} & \text{if}  n=0 \\
\end{array} }\right.$$\displaystyle \begin{array}{ll}
\text{S}s_{n-1}\text{RBL}s_{n-1}\text{LBR}s_{n-1}\text{G} & \text{if}  n>0 \\
\text{F} & \text{if}  n=0 \\
\end{array}$        h = RBLLB.

Figure 4: The sets produced by the commands for s2, h, and S2 in the construction of the Sierpinski gasket. Here, the set for s1 is drawn thicker within that of s2.
\begin{figure}\centerline{\psfig{figure=turtle502.eps,height=1in}} \end{figure}

As in the previous sections, once we have worked out the algorithm, writing the maple code to implement it is quite straightforward. We we will use the name Sierp for the procedure that produces sn, and Sierpinski for the procedure to produce Sn.

> 
  Sierp:=proc(n::nonnegint)
    if (n=0) then
       `F`;
    else
       cat(`S`,Sierp(n-1), `RBL`, Sierp(n-1), `LBR`, Sierp(n-1), `G`);
    fi;
  end:

> 
  Sierpinski:= n -> cat( Sierp(n), `RBLLB`):

Since we also need to set the angle and scale appropriately, we can combine them all into a single command DrawSierp:

> 
  DrawSierp:= proc(n::nonnegint)
     SetTurtleAngle(60);
     SetInitTurtleHeading(0);
     SetTurtleScale(.5);
     TurtleCmd(Sierpinski(n));
  end:

> 
  DrawSierp(9);

\begin{mfigure}\centerline{\psfig{width=3in,angle=270,figure=turtle503.eps}}\end{mfigure}

Warning: Drawing even $ \Cal{S}_8$ takes a significant amount of time and is almost indistinguishable from $ \Cal{S}_7$. If you try to draw $ \Cal{S}_9$, be prepared to wait quite a while, and make sure your computer has plenty of memory.



Footnotes

... this5.18
We will give another solution which is closer to our original description in §9.

next up previous
Next: Inside the turtle's shell Up: A turtle in a Previous: Cantor sets

Translated from LaTeX by Scott Sutherland
2002-08-29