## More Pi

In a previous post I’ve explained how we can estimate the number Pi using Monte Carlo Methods (basically throwing darts at a circle). I personally think this method is quite elegant, but it is not particularly efficient. It might take a very, very, very long time for it to converge to anything close to the actual number. Still, pretty awesome.

This week I’ve compiled a simple, interactive and more visual example using the jQuery library and SVG graphics. You can find it here. Let me know what you think.

**Update (april 2nd 2011):** Code for this project is now available on Github.

Advertisements

I suppose one way to make this more efficient is to use symmetry. Dividing the image in four quarters makes it 4 times faster. You can also exclude the inner half of a quadrant, saving another factor 2. Etc.

After that, you need some sort of way to avoid putting dots in a place that you already know is inside the circle. Or some other way to get closer and closer to the interesting area.

Sjors ProvoostNovember 7, 2010 at 21:30

Symmetry will not do you any good. Remember that we are interested in the ratio of the surface areas; dividing the image in four parts is similar to multiplying both the numerator and the denominator by four. It won’t increase the speed of convergence.

Excluding some parts of the image might help, but only if you know the exact fraction of both bodies you are excluding and come up with an efficient way to select random points uniformly distributed over the area you are including. I’m guessing just selecting random points in a square is faster. (certainly easier to implement…)

Thanks for your input! If you come up with a more efficient strategy be sure to let me know; I’ll implement it if I can.

lukasvermeerNovember 8, 2010 at 20:16