a reproducible gallery of statistical graphics

- vis@supstat.com
- github.com/supstat
- twitter.com/supstat
- weibo.com/supstat

Given a needle of length dropped on a plane ruled with parallel lines units apart, what is the probability that the needle will cross a line? This question is first posed in the 18th century by Georges-Louis Leclerc, Comte de Buffon. The answer is where is the distance between two adjacent lines, and is the length of the needle.

The solution, in the case where the needle length is not greater than the width of the strips, can be used to design a Monte Carlo method for approximating the number .

In the **animation** package, the function `buffon.needle()`

can be
used to simulate Buffonâ€™s needle. There are three graphs made in each step: the top one is a
simulation of the scenario, the bottom-left one can help us understand the connection between
dropping needles and the mathematical method to estimate , and the bottom-right one is the
simulation result for each drop.

```
library(animation)
ani.options(nmax = 100, interval = 0.5)
par(mar = c(3, 2.5, 0.5, 0.2), pch = 20, mgp = c(1.5, 0.5, 0))
buffon.needle(mat = matrix(c(1, 2, 1, 3), 2))
```

You can use larger `nmax`

values in the code to drop the needle for more times.