Skip to content

Commit d9bce12

Browse files
committed
make sure points are uniformly distributed
1 parent d8f3eab commit d9bce12

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "random-location",
3-
"version": "1.0.5",
3+
"version": "1.0.6",
44
"description": "Random coordinates within a circle given a center point and radius",
55
"main": "src/index.js",
66
"scripts": {

src/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ Where -90 <= A <= 90 and -180 <= B <= 180.
5757
radius R is in meters.
5858
*/
5959
const randomCirclePoint = (centerPoint, radius) => {
60-
return randomCircumferencePoint(centerPoint, Math.random() * radius)
60+
// http://mathworld.wolfram.com/DiskPointPicking.html
61+
return randomCircumferencePoint(
62+
centerPoint,
63+
Math.sqrt(Math.random()) * radius
64+
)
6165
}
6266

6367
/*

0 commit comments

Comments
 (0)