In this Discussion

Playing pool with Pi

I saw this topic on another forum and thought I’d try it with Codea. The subject is calculating the value of Pi by counting the number of collisions using 2 balls and a wall. What this program shows is a red ball moving towards a blue ball. I count the number of collisions that the blue ball has with the wall and the red ball. That count gives the value of Pi. Using M1 mass of 100 and M2 mass of 1, I can only get Pi to 1 decimal position. To get 2 positions, M1 has to be 1,000. 3 positions, M1 has to be 10,000, etc. The Codea Physics engine doesn’t work right if I use M1 mass with 1,000 or higher. That’s just too much of a mass difference between the 2 balls. This example for 1 digit is sufficient to show how this works. For more info, do a Google search on “Playing pool with Pi”.

@Simeon Here’s a mathematical version of the graphics. This code was originally written in TiBasic by redsmith in another forum that I visit. I tried the original code on my TI 84 Plus SE and it worked, but was extreamly slow even for a few digits. I rewrote the code to run on the iPad. Use the slider to select the number of digits then press calc. It takes about 20 seconds to calculate 8 digits on my iPad Air. Each additional digit results in an increase of 10x. So 9 digits will take around 200 seconds.