Message Boards Message Boards


Showing a Fractal Line

Posted 3 years ago
3 Replies
6 Total Likes

At my article Squeezing Pi from a Menger Sponge, I introduced the Happy Pi fractal. I started with the Wallis formula.


And then I gave code there for alternately chopping and lengthening segments. After many steps, the total length of the segments would be equal to Pi.

Happy Pi Fractal

Unfortunately, it gets pretty tricky to see what's going on with a fractal line. One way to get a better visualization of the fractal line is to map it to a space-filling curve of some sort. One of the simplest is the double spiral.

PolarPlot[{t, -t}, {t, 0, 10 Pi}, Axes -> False] 

double spiral

We can use that to map segments of the fractal line to arcs of the double spiral.

Show[PolarPlot[Sign[#[[1]]] t, {t, Abs[#[[1]]], Abs[#[[2]]]}, Axes -> False, 
    PlotStyle -> {Black, Black}] & /@ ((Partition[Last[FoldList[fractionfractal[#1, #2] &, {0, 4}, 
         Table[((2 n + 1 - (-1)^n)/2)/((2 n + 1 + (-1)^n)/2), {n, 2, 16}]]], 2] - 2) 60 Pi)]

happy pi spiral

Not as enlightening as I was hoping it would be.

Another space-filling curve is shown at Hilbert and Moore Fractal Curves. Combining the Hilbert Curve and the fractal line yields something like the following.

Happy Pi Hilbert

A little bit of explanation for how that was made -- first I generated a Hilbert sequence.


Then I did the Z-order curve of the sequence. I combined the result with the fractal line, but I need better code than what I've got so far.

Graphics[Line[(FromDigits[#, 2] & /@ Reverse[Transpose[Partition[#, 2]]] & /@ IntegerDigits[hilbert, 2, 8])]] 

hilbert curve

It seems to me that there might be a fractal partial-space-filling curve related directly to the Wallis formula. Does anyone see a way to do that?

Wallis formula

3 Replies

enter image description here - another post of yours has been selected for the Staff Picks group, congratulations !

We are happy to see you at the top of the "Featured Contributor" board. Thank you for your wonderful contributions, and please keep them coming!

It looks quite amazing! But I don't quite understand what you are doing? What are the lengths? The fraction 2/3, 4/3, 4/5, 6/5 and so on?

What causes the big gap in the spiral?

Yes, amazing! Your method of generating the Hilbert curve seems to be very elegant and efficient - but I have problems understanding it. E.g. where does the "Hilbert sequence" come from? Wikipedia obviously does not know such thing ...

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract