buffon.needle {animation}R Documentation

Simulation of Buffon's Needle

Description

This function provides a simulation for the problem of Buffon's Needle, which is one of the oldest problems in the field of geometrical probability. `Needles' are denoted by segments in the plane, and dropped randomly to check whether they cross the lines. Through many times of `dropping' needles, the approximate value of pi can be calculated out.

Usage

buffon.needle(l = 0.8, d = 1, redraw = TRUE, 
    control = ani.control(interval = 0.05, nmax = 100), ...)

Arguments

l numerical. length of the needle; shorter than d.
d numerical. distances between lines; it should be longer than l.
redraw logical. redraw former `needles' or not for each drop.
control control parameters for the animation; see ani.control
... other arguments passed to ani.control

Details

This is quite an old problem in probability. For mathematical background, please refer to http://en.wikipedia.org/wiki/Buffon's_needle or http://www.mste.uiuc.edu/reese/buffon/buffon.html.

Value

The values of estimated pi are returned as a numerical vector (of length nmax).

Note

Note that redraw will affect the speed of the simulation (animation) to a great deal if the control argument nmax (in control) is quite large, so you'd better specify it as FALSE when doing large amount of simulations.

Author(s)

Yihui Xie

References

Ramaley, J. F. (Oct 1969). Buffon's Noodle Problem. The American Mathematical Monthly 76 (8): 916-918.

See Also

ani.start, ani.stop

Examples

# it takes several seconds if 'redraw = TRUE' 
buffon.needle(nmax = 500, interval = 0)

# this will be faster 
buffon.needle(nmax = 500, interval = 0, redraw = FALSE)

## Not run: 
 
# create HTML animation page
ani.start()
buffon.needle(saveANI = TRUE, nmax = 100, interval = 0.05, 
    width = 600, height = 600, redraw = FALSE) 
ani.stop() 

## End(Not run)

[Package animation version 0.2-0 Index]