Skip to content

Commit

Permalink
make sure points are uniformly distributed
Browse files Browse the repository at this point in the history
  • Loading branch information
sagi committed Aug 14, 2017
1 parent d8f3eab commit d9bce12
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "random-location",
"version": "1.0.5",
"version": "1.0.6",
"description": "Random coordinates within a circle given a center point and radius",
"main": "src/index.js",
"scripts": {
Expand Down
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ Where -90 <= A <= 90 and -180 <= B <= 180.
radius R is in meters.
*/
const randomCirclePoint = (centerPoint, radius) => {
return randomCircumferencePoint(centerPoint, Math.random() * radius)
// http://mathworld.wolfram.com/DiskPointPicking.html
return randomCircumferencePoint(
centerPoint,
Math.sqrt(Math.random()) * radius
)
}

/*
Expand Down

0 comments on commit d9bce12

Please # to comment.