Points are randomly scattered inside the unit square, some fall within the unit circle with probability $P=\pi/4$.
so $P$ is approximated by the fraction $$P\approx \frac{\text{Number of red points}}{\text{Number of all points}}$$ this leads $$\pi \approx 4\frac{\text{Number of red points}}{\text{Number of all points}}$$ (see following image)
There is a code for this:
tinyColor[color_, point_] := {PointSize[Small], color, Point[point]}
colorChoose[point_] :=
If[Norm[point] <= 1, tinyColor[Red, point], tinyColor[Blue, point]]
darts = RandomReal[{0, 1}, {40000, 2}];
coloredDarts =ParallelMap[colorChoose, darts];
insides = Map[Boole[Norm[#] <= 1] &, darts];
piapprox = Accumulate[insides]/Range[Length[darts]]
inner = Select[darts, Norm[#] <= 1 &];
outer = Select[darts, Norm[#] > 1 &];
Show[Plot[Sqrt[1 - x^2], {x, 0, 1}, Filling -> Axis, AspectRatio -> 1,
PlotLabel -> n == Length[darts] TildeTilde[π, 4.0*piapprox[[-1]]]],
ListPlot[{inner, outer},
PlotStyle -> {{PointSize[Tiny], Red}, {PointSize[Tiny], Blue}},
ImageSize -> {500, 500}]]
I tried to simplify this problem:
pts = RandomPoint[Rectangle[], 40000];
ListPlot[pts, AspectRatio -> 1, PlotStyle -> Blue]
The problem is following:
How can I split set of points pts
into two parts, "inside the circle " and "outside the circle"?
rf = RegionMember[Disk[]]; rf[darts]
$\endgroup$