I first learned about Processing at Maker Faire in 2011. I don’t consider myself a visual artist, but Processing made it straightforward to create beautiful graphics using code. However, I didn’t want to go through the hassle of working with the Processing IDE, so I set it aside for a couple years.
In my last post, I discussed a method for approximating π which I later learned was a Monte Carlo method, thanks to some helpful Redditors. Today I’ll talk about technique that uses numerical integration (specifically, the rectangle method) to produce a more accurate result in less time. Continue reading
Consider a square with an inscribed circle of radius r which itself has an inscribed square rotated 45 degrees. If we look at just the first quadrant, then the area of the outermost square Aouter is r2. The area of the circle Acircle is πr2/4, and the area of the inner triangle Atriangle is r2/2. Therefore, we can make two equations for π based on the ratios of these areas: π = 4Acircle/Aouter and π = 2Acircle/Atriangle. Notice how neither equation depends on the radius; so, if we can figure out an alternate way to calculate these areas, we can determine the value of π. Python to the rescue!