/*Demonstrates Buffon's needle problem interactive solution: "Suppose we have a floor made of parallel strips of wood, each the same width, and we drop a needle onto the floor. What is the probability that the needle will lie across a line between two strips?" Jean Louis Leclerc, Comte de Buffon (1777). Buffon's needle was the earliest problem in geometric probability to be solved. The solution, in the case where the needle length is not greater than the width of the strips, is used here as a Monte Carlo method for approximating the number Pi. You can set the number of parallel lines per image and choose between preset numbers of needles thrown. After needles and line grid are generated you will need to use [Multipoint Tool] (already selected by macro) to click on intersections between needles and a set of parallel lines. Macro will wait for you to finish selection and click [OK] button. Parameters such as probability of a needle hitting parallel line, needle length, distance between parallel lines and Pi value are presented in separate window "Buffon's needles". It allows comparing calculated and estimated values. Version: 1.0 Date: 03/11/2018 Author: Aleksandr Mironov amj-box@mail.ru */ //help html = "" +"

# Buffon's needle problem interactive solution, v1.0

" +"Suppose we have a floor made of parallel strips of wood,
" +"each the same width, and we drop a needle onto the floor.
" +"What is the probability that the needle will lie across
" +"a line between two strips?

" +"____________________________Jean Louis Leclerc, Comte de Buffon (1777)

" +"Buffon's needle was the earliest problem in geometric probability
" +"to be solved. The solution, in the case where the needle length
" +"is not greater than the width of the strips, is used here as
" +"a Monte Carlo method for approximating the number Pi.

" +"You can set the number of parallel lines per image and choose
" +"between preset numbers of needles thrown.

" +"After needles and line grid are generated you will need to use [Multipoint Tool]
" +"(already selected by macro) to click on intersections between needles and
" +"a set of parallel lines.

" +"Macro will wait for you to finish selection and click [OK] button.

" +"Parameters such as probability of a needle hitting parallel line, needle length,
" +"distance between parallel lines and Pi value are presented in separate window
" +"[Buffon's needles]. It allows comparing calculated and estimated values.
" Dialog.create("Buffon's needles, ver. 1.0"); Dialog.addNumber("Number of parallel lines", 12, 0, 4, "per image"); Dialog.addChoice("Number of needles per image", newArray(50, 1, 10, 20, 100, 200, 500, 1000)); Dialog.addHelp(html); Dialog.show(); newImage("New", "8-bit black", 1024, 1024, 1); getDimensions(width, height, channels, slices, frames); //lines parameters LinesNumber = Dialog.getNumber();; T = height/LinesNumber; setLineWidth(1); setColor("green"); //Draw lines for (y=T; y (width-NdlLength)) { leg1 = -abs(leg1); } if(y1 < NdlLength) { leg2 = abs(leg2); } if(y1 > (height-NdlLength)) { leg2 = -abs(leg2); } //Needle end coordinates x2 = x1 + leg1; y2 = y1 + leg2; //Creating a needle setLineWidth(NdlWidth); setColor(NdlColor); Overlay.drawLine(x1, y1, x2, y2); Overlay.show; }