# Buffon’s Needle

By Allan Roberts

Figure 1. A simulation of Buffon’s Needle Experiment. An estimate for Pi has been computed from the proportion of needles crossing the horizontal lines (n = 100,000; not all lie within the margins of the figure).

Today is π Day. Which is sort of actually a real holiday (Lamb 2012). (But not, presumably, a rational holiday.) And what better way to celebrate π Day than with a probabilistic estimation of π? The R script provided below will simulate a version of Buffon’s Needle experiment, and use the proportion of needles crossing the horizontal lines to estimate π. (For details on Buffon’s Needle see the Wikipedia article cited below.)

π, what is it good for? Well, it gets used in the formulas for the area of a circle, and the volume of a sphere. It’s also a constant in the formula for the probability density function for the normal distribution. Thus every time you make an assumption of normality, you are making a tacit reference to π.

R Script

BuffonsNeedle <- function(n=100, sd=2){
#Implemented in R by Allan Roberts, 2013.

plot.new();
par( usr = c(-2,12,-2,12), mar=c(4,4,4,4) );
arrows(rep(-4,16),-2:12, rep(14,16),-2:12, length=0);

X <- rnorm(n,5,sd);
Y <- rnorm(n,5,sd);
Angle <- runif(n,0,2*pi); #Note: the script itself uses pi. Homework: write a pi-less version.
X2 <- X + cos(Angle);
Y2 <- Y + sin(Angle);
CrossesLine <- ( floor(Y) != floor(Y2) );

arrows(X[!CrossesLine],Y[!CrossesLine],X2[!CrossesLine],Y2[!CrossesLine],length=0,col=rgb(0,1,0),lwd=1);

arrows(X[CrossesLine],Y[CrossesLine],X2[CrossesLine],Y2[CrossesLine],length=0,col=rgb(0,0.5,0,0.5),lwd=1);

p <- sum(CrossesLine)/n;
return(c(p,2/p));
}

BuffonsNeedle( );

References

Buffon’s needle. Wikipedia. http://en.wikipedia.org/wiki/Buffon%27s_needle

Lamb, Evelyn. July 21, 2012. Pi Approximation Day Celebrated July 22, How Much Pi Do You Need? Huffington Post.

Pi Day. Wikipedia.