Created
October 16, 2017 07:22
-
-
Save arxeiss/8e2ad2c06f929dd6589ae8df19852ed0 to your computer and use it in GitHub Desktop.
Code
This file contains 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
// 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