The simplest approach - to use uniformly distributed points with (random(), random()) - doesn’t work,
because there will be areas with high density of points and areas with no points at all.
-Such distribution doesn’t look natural.
Caption
Various types of grids with gaps can give even distribution, but the picture will not look random.
There will always be a pattern, sometimes more visible, sometimes less, but still visible. This
doesn’t look natural either.
We need to generate a random point in a circle with uniform distribution.
A naive approach with picking a random angle and a random distance doesn’t have uniform distribution -
-there are more points close to center and fewer points at the radius.
-This article
-has explanation and visualization.
Another approach is to generate uniformly distributed random points in the bounding box of the circle
-and pick the first point that is inside the circle.
With random() being a uniformly random number, the naive approach for a point in a square:
x = random()
-y = random()
-
give uniformly distributed points. And x * x + y * y <= R * R provides an easy test for
-point being inside the circle.
Obvious drawback - undefined number of attempts, but with uniformly distributed points in a box the average
-amount of attempt should not be greater than 2.
-
\ No newline at end of file
+https://andreynautilus.github.io/posts/2024-07-29-random-points-in-circle/
+
\ No newline at end of file
diff --git a/docs/posts/2024-07-29-random-points-in-circle/index.html b/docs/posts/2024-07-29-random-points-in-circle/index.html
new file mode 100644
index 0000000..28f86d1
--- /dev/null
+++ b/docs/posts/2024-07-29-random-points-in-circle/index.html
@@ -0,0 +1,111 @@
+Random points in circle with uniform distribution | Andrey Nautilus blog
+
We need to generate a random point in a circle with uniform distribution.
A naive approach with picking a random angle and a random distance doesn’t have uniform distribution -
+there are more points close to center and fewer points at the radius.
+This article
+has explanation and visualization.
NNN points, left to right: naive approach, correct formula, Monte Carlo (XXX attempts)
Another approach is to generate uniformly distributed random points in the bounding box of the circle
+and pick the first point that is inside the circle.
With random() being a uniformly random number, the naive approach for a point in a square:
x = random()
+y = random()
+
give uniformly distributed points. And x * x + y * y <= R * R provides an easy test for
+point being inside the circle.
Obvious drawback - undefined number of attempts, but with uniformly distributed points in a box the average
+amount of attempt should not be greater than 2 (on average we need 4 / PI attempts).
+
\ No newline at end of file
diff --git a/docs/posts/index.html b/docs/posts/index.html
index 389f2f3..91eed20 100644
--- a/docs/posts/index.html
+++ b/docs/posts/index.html
@@ -1,6 +1,6 @@
posts | Andrey Nautilus blog