Last active
May 9, 2017 13:04
-
-
Save EmmanuelGuther/0bd32ac88f912eb67c84c76650771d52 to your computer and use it in GitHub Desktop.
These functions are for to generate points uniformly, randomly, and independently within a circle of radius r around a location (x0, y0),
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*These functions are for to generate points uniformly, randomly, and independently | |
within a circle of radius r around a location (x0, y0), | |
*/ | |
function latAndlonGenerator (radius) { | |
const RADIUS_IN_METERS = 70000 | |
let r = RADIUS_IN_METERS / 111300, // Convert meters in degrees (111,300 meters = a degree.) | |
y0 = 40.416775, // Central point where to generate more coordinates, inside a circle | |
x0 = -3.70379, // In this case, Madrid. | |
u = Math.random(), | |
v = Math.random(), | |
w = r * Math.sqrt(u), | |
t = 2 * Math.PI * v, | |
x = w * Math.cos(t), | |
y1 = w * Math.sin(t), | |
x1 = x / Math.cos(y0) | |
newY = y0 + y1 | |
newX = x0 + x1 | |
return {lat: newY, lon: newX} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment