Skip to content

Instantly share code, notes, and snippets.

@EmmanuelGuther
Last active May 9, 2017 13:04
Show Gist options
  • Save EmmanuelGuther/0bd32ac88f912eb67c84c76650771d52 to your computer and use it in GitHub Desktop.
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),
/*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