From 14136d712f2e5063a7e638ffd70c8f3b13c919b9 Mon Sep 17 00:00:00 2001 From: Rapen765 Date: Sat, 19 Oct 2024 22:20:59 +0200 Subject: [PATCH] Fixed rand_in_circle to ensure uniform distribution of points --- arcade/math.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/arcade/math.py b/arcade/math.py index f8494d480f..a14b85c33c 100644 --- a/arcade/math.py +++ b/arcade/math.py @@ -224,10 +224,7 @@ def rand_in_circle(center: Point2, radius: float) -> Point2: Generate a point in a circle, or can think of it as a vector pointing a random direction with a random magnitude <= radius. - Reference: https://stackoverflow.com/a/30564123 - - .. note:: This algorithm returns a higher concentration of points - around the center of the circle + Reference: https://stackoverflow.com/a/50746409 Args: center (Point2): The center of the circle @@ -236,7 +233,7 @@ def rand_in_circle(center: Point2, radius: float) -> Point2: # random angle angle = 2 * math.pi * random.random() # random radius - r = radius * random.random() + r = radius * math.sqrt(random.random()) # calculating coordinates return (r * math.cos(angle) + center[0], r * math.sin(angle) + center[1])