Learn R Programming

animation (version 0.2-0)

buffon.needle: 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

Value

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

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.

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

Run this code
# 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)

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

Run the code above in your browser using DataLab