Skip to content

Instantly share code, notes, and snippets.

@arxeiss
Created October 16, 2017 07:22
Show Gist options
  • Save arxeiss/8e2ad2c06f929dd6589ae8df19852ed0 to your computer and use it in GitHub Desktop.
Save arxeiss/8e2ad2c06f929dd6589ae8df19852ed0 to your computer and use it in GitHub Desktop.
Code
// Random generator of position in circle
// Test out on http://testdata.kutac.cz/nahodna-pozice-v-kruhu/
function getCircleRandomPosition(radius){
a = Math.random();
b = Math.random();
var ret = {
x: 0,
y: 0
}
if (a > 0 || b > 0) {
if (b < a) {
var x = a;
a = b;
b = x;
}
ret.x = radius * b * Math.cos(2 * Math.PI * a/b);
ret.y = radius * b * Math.sin(2 * Math.PI * a/b);
}
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment