CodingTrain / Suggestion-Box

A repo to track ideas for topics
568 stars 86 forks source link

Pi Day 2023 - Visualization of Pi via the Chaos Game #1782

Open SilvestriStefano opened 1 year ago

SilvestriStefano commented 1 year ago

Hello, I know it is kind of early for $\pi$ day, but here is my suggestion for a short challenge on it: visualize $\pi$ via the Chaos Game. It is another way to show (visually) that its digits are actually random. I have made a version of it with p5js using only 50k digits. pi_visualized

The great Shiffman made videos on the Chaos Game in the past (Coding Challenge 123 part 1 and part2), so it shouldn't be new to the fans, but I will provide a short explanation of what you see above.

You start with 10 equally spaced points on a circle that represent the digits {0,1,2,3,4,5,6,7,8,9}. Pick also another point in the plane (in the picture above, if you look closely you can see I started at the center of the circle). In the Chaos Game you will then randomly choose one of those points on the circle, move a certain distance towards it, and repeat indefinitely. However, this time, we will choose the point on the circle following the digits of $\pi$: we will first move towards the point representing $1$, then towards $4$, then $1$, then $5$, then $9$, and so on. You may ask how much should we move towards each point? whatever we want! I used $(\sqrt{5}-2)$, so at every step we move approximately $0.236$ of the distance between the current and the target point. I calculated this number using a formula that guarantees just-touching shapes [^1]. The fact that we obtain the same final picture following either method, shows that there is no discernible pattern in the digits of $\pi$, i.e. they are random.

Further variations

What if we read the digits of $\pi$ two at a time? That is we have a two-digit number $14$, $15$, $92$, etc. instead of $1$, $4$, $1$, $5$, $9$, $2$, etc. Should we use 100 equally spaced points on the circle? Sure, but since 100 is divisible by 4 and 5, we can group the two-digits into 4 or 5 groups or take them modulo 4 or 5. Therefore we could use only 4 or 5 equally spaced points on the circle.

What shape should we expect to obtain?

[^1]: Refer to Larry Riddle at Agnes Scott College or the article by Schlicker and Dennis, "Sierpinski n-gons", Pi Mu Epsilon Journal, 10 (1995), No. 2, 81-89.