Skip to content

About

Interactive Buffon's needle laboratory with Monte Carlo experiments, Rapier rigid-body physics, and reproducible exports

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Buffon’s Match Lab

An interactive numerical laboratory, with an optional Three.js / Rapier implementation.

Local updates — September 23, 2026

The current checkout includes a persistent Light / Dark / System selector (default: System), a corrected Rapier ESM import, and removal of the former 1,000-body physical-mode cap. All 31 automated tests pass with the pinned dependencies installed, including three Rapier tests and an actual 1,200-body creation/stepping check. Syntax checks pass for 28 JavaScript modules. Browser checks cover theme selection, persistence, live system-theme changes, and mobile layout in both editions. This is not a physical calibration or a large-population performance benchmark.

The supplied package's validation reports and release-status notes below describe its original packaging environment; their statements that Rapier was not executed are historical. SHA256SUMS.txt describes the files published in this repository.

Start with one wooden match, repeat the 163-match demonstration, or explore hypothetical populations through 10^48. The program keeps actual geometric trials, physical-drop code, and model-based aggregate draws visibly distinct.

Release status: the numerical engine and offline Canvas application have been tested. The Three.js / Rapier adapters are implemented, but their dependencies could not be downloaded in the packaging environment, so their real integration was not executed. This is a development build, not completion of every requirement in the supplied 87-section specification, a physically calibrated instrument, or a production-readiness certification. See the implementation map and the validation report.

Open it now — no installation

Unzip this package and open Buffons-Match-Lab.html in a modern desktop browser.

This self-contained edition runs the real ideal Monte Carlo and aggregate implementations locally. It includes the shaded Canvas board, camera controls, charts, uncertainty intervals, repeated studies, manual calculator, configuration import, integrity checks, and exports. It needs no account, API key, external font, CDN, or Node.js installation. Numerical work is cooperatively chunked on the main thread; it is not a fake worker or a remotely computed result.

The standalone file is the numerical / Canvas edition only. It does not contain or remotely download the optional 3D libraries. Browser restrictions can prevent persistent local storage when opening a file; exporting configuration JSON remains the portable way to save settings.

Run the installable application

Install Node.js 22 or newer, open a terminal in this directory, and run:

npm install --ignore-scripts
npm start

Open the local address printed by the server, normally:

http://127.0.0.1:4173

The exact direct dependencies are Three.js 0.180.0 and @dimforge/rapier3d-compat 0.17.3. They are not bundled in this ZIP. Installation needs access to the npm registry. A genuine npm lockfile will be created by installation; no invented lockfile or integrity values are supplied.

Windows users can run start-windows.cmd. On macOS or Linux:

./start-macos-linux.sh

The launchers attempt dependency installation and then open the local application. The server binds only to 127.0.0.1, serves files read-only, and has no remote simulation service. Stop it with Ctrl+C. Set PORT to select another local port.

npm start also works without installation: it uses the labeled Canvas preview and disables actual physical drops. When the libraries are installed, the local app attempts GPU-instanced WebGL rendering. A WebGL initialization error returns to the Canvas renderer, not to a fabricated physical solver.

What the modes mean

Selection Computation Important interpretation
Ideal + explicit Every trial draws a position and orientation and tests an intersection. The reference numerical experiment. No falling animation is passed off as physics.
Ideal / Hybrid + automatic Explicit geometry up to an adjustable threshold, then aggregate sampling. Hybrid is a statistical execution selector, not extrapolation of measured physical throws.
Aggregate Samples crossing counts from the ideal model, using binomial beta splitting or a disclosed rounded-normal approximation. Its input probability uses reference π. It is not independent evidence for π.
Physical, installable app Rapier compound rigid bodies, fixed timesteps, contact response, post-rest measurement, finite-board policies. Adapter source is included, but real-engine validation remains outstanding. Physical intervals are descriptive.

For the default L = 45 mm and D = 90 mm, the estimate is N/C. Other spacings use the corresponding coefficient. Matches longer than the spacing use the at-least-one-crossing formula, not the short-needle formula. Zero crossings produce an undefined point estimate and an unbounded upper interval endpoint.

The sidebar contains configurable box, case, pallet, and truck assumptions. Defaults are 40 × 100 × 100 × 20 = 8,000,000 matches per truckload, solely a scenario convention. “All matches ever created” starts at an editable hypothetical value; it is not a historical manufacturing estimate.

Using the laboratory

Physical mode has no fixed 1,000-body limit. Every requested match uses a real Rapier body; available browser memory and simulation time determine practical capacity. The existing physical timeout still applies, and unresolved bodies are reported without being counted as settled. Counts must fit JavaScript's exact integer range (up to 9,007,199,254,740,991); this precision boundary is not a claim that such a run fits in memory.

Choose the quantity, seed, length, spacing, and computational mode, then press THROW THEM ALL. Large explicit runs update in batches. Pause, resume, cancel, or replay without changing the final deterministic crossing result for a fixed configuration. Changes to the pending experimental settings take effect on the next run; camera and display controls operate on the current visualization.

Drag the board to orbit, scroll to zoom, or choose top-down / tabletop / macro views. The Canvas board also accepts arrow keys and + / −. Click a recorded match to inspect its geometry. “Mark crossings” uses a cross marker in the Canvas renderer, not only a color change. At massive scale, read the representation label: aggregate specimens are independent illustrative geometry, not members recovered from the sampled aggregate count.

The five charts show convergence, error scaling, orientation, line-relative position, and parameter space. The notebook overlays recent session runs. Repeated-study mode reports finite and undefined estimates separately; mean, median, variance, RMSE and quantiles exclude undefined estimates, while interval inclusion uses all runs.

The confidence challenge uses an anytime-valid, conservative alpha-spending Hoeffding rule. It does not stop just because the estimate briefly looks close to π. Its planning projection is a separate fixed-sample approximation, not a promise of the stopping time.

Exports and reproducibility

Export run provides a SHA-256-protected JSON manifest, checkpoint CSV, SVG chart, current-board PNG, self-contained HTML report, and configuration JSON. The repeated-study panel has a separate study export. Named configurations can be stored locally, and hosted installations can encode settings in a URL. The standalone edition shares configuration JSON rather than inventing a hosted URL.

Counts in JSON are decimal strings. Keep them as strings or arbitrary-precision integers. When importing CSV into spreadsheet software, explicitly import count columns as text; otherwise the receiving software can round large integers. Full decimal bounds and estimates are available in exports and metric tooltips. A narrow interval is displayed as its nonzero width when short rounded endpoints would look identical.

A manifest hash detects changes relative to the recorded hash. It is not a digital signature and does not authenticate the author. Reproduction requires the same source version, algorithm, configuration, and compatible runtime. Cross-browser transcendental arithmetic and cross-hardware physics determinism are not promised. Camera, rendering quality, and recorded-sample limits do not consume the experimental RNG stream.

Run the checks

npm test
npm run check
npm run validate
npm run benchmark
npm run build:standalone

The optional independent verification and screenshot harness use Python:

python -m pip install -r requirements-validation.txt
python scripts/verify_independent.py
python scripts/browser_validate.py --chromium /path/to/chromium

On an unrestricted test machine with the local server running, test the module / worker edition with:

python scripts/browser_validate.py --url http://127.0.0.1:4173 --chromium /path/to/chromium

The default screenshot harness executes the actual standalone application inside an empty Chromium document. This was necessary because the packaging browser blocks navigation to local URLs. It does not alter browser security policy, inject expected crossing counts, or mock the simulator. The expected manifests are used only for assertions after fresh computation.

After installing the 3D dependencies, run the test suite again. The two gated Rapier tests should execute rather than skip. Their presence is not evidence they have already passed. Perform the additional checks in next steps before treating physical outcomes or visual fidelity as validated.

Delivered evidence

The package contains 28 passing automated tests, 2 skipped Rapier integration tests, 24 ratio/seed checks, independent Python checks of 19 interval/estimator cases and seven one-million-trial geometric experiments, plus 47 browser checks. Exact logs, seeds, configuration, environmental details, and results are in validation/.

There are real browser captures for 1, 40, 163, 1,000, 1,000,000, one configurable truckload, 1,000,000,000, 10^12, hypothetical 10^24, and the supported 10^48 limit, plus study and mobile views. No physical-drop screenshot is supplied, because that integration was not run.

Layout

Buffons-Match-Lab.html     Self-contained numerical / Canvas edition
src/core/                 Arithmetic, RNG, geometry, statistics, samplers, channels, manifests
src/physics/              Optional Rapier adapter
src/render/               Canvas preview and optional Three.js PBR renderer
src/ui/                   Native SVG charts and study summaries
src/main.js               Application controls, state, interactions, exports
scripts/                  Local server, build, benchmark and validation tools
tests/                    Deterministic, statistical, channel and gated physics tests
validation/               Actual run manifests, CSVs, logs, studies, browser exports and screenshots
docs/                     Scientific notes, architecture, full requirement map and original specification

The most consequential remaining work is real-engine verification and empirical physical calibration, production-quality photorealism, GPU statistical computation, multi-worker execution, and the deferred research / presentation features enumerated in the requirement map. The numerical app remains usable without claiming those features exist.

About

Interactive Buffon's needle laboratory with Monte Carlo experiments, Rapier rigid-body physics, and reproducible exports

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages