Estimating pi with p5.js and Monte Carlo sampling.
- Points are randomly sampled from inside a square with side length
2r
. - The total number of points
= N_total
. - Points that fall inside the circle with radius
= r
that lies inside the square are tallied= N_inside
. - Pi is then estimated as
pi = 4 * N_inside / N_total
.