4 ms·
The thinking goes more like this: I want to get a random point in a circle. What parameters make up a point in a circle? Radius and angle can be one, so let'
by toxicFork 4y ago
The thinking goes more like this:
I want to get a random point in a circle.
What parameters make up a point in a circle?
Radius and angle can be one, so let's randomise those.
This is something that's done a lot in game development.
- eru 4y agoAnd it _is_ a random point in a circle. Just not a uniformly distributed one. Btw, here's a way to sample a uniform random point on the edge of a circle without trigonometric functions: Sample x and y coordinates from a standard normal distribution. Then project the result on the circle, by normalising the distance. (You can approximate normal distributions fairly easily. Or your favourite computing environment might have specialised optimized machinery built-in.)
- toxicFork 4y ago> Sample x and y coordinates from a standard normal distribution. Then project the result on the circle, by normalising the distance. I wonder if that's uniform... I expect that you would have more points mapped to the corners.
- keefe8 4y agoIt appears to be uniform. I tested empirically in Python: https://pastebin.com/raw/ca03uywJ https://pastebin.com/raw/ca03uywJ
- toxicFork 4y agohttps://codepen.io/toxicfork/pen/OJQzLba https://codepen.io/toxicfork/pen/OJQzLba This says otherwise
- Malipeddi 4y agoNormal distribution is not the same as uniform distribution. I edited in a normal distribution sampler in your codepen example. https://pastebin.com/raw/CP4yNRE9 https://pastebin.com/raw/CP4yNRE9
- toxicFork 4y agoI see, thanks!
- eru 4y agoBtw, the following two are equivalent (in JavaScript syntax): var a = Math.max(Math.random(), Math.random()); var b = Math.sqrt(Math.random());
- toxicFork 4y agoCurious, how come? Does it become a statistical thing?
- eru 4y agoWell, not sure whether you'd call it statistics. It's a mathematical fact from probability theory. And it doesn't matter how often you sample: the distributions themselves are the same. I came across that one in the other direction, when trying to work out how to make weighted rendezvous hashing work. See https://en.wikipedia.org/wiki/Rendezvous_hashing https://en.wikipedia.org/wiki/Rendezvous_hashing
- keefe8 4y agoI meant to show the output of my code, but Pasteboard was down at the time: https://gcdnb.pbrd.co/images/f8bgGZMW3deq.png?o=1 https://gcdnb.pbrd.co/images/f8bgGZMW3deq.png?o=1
- whyever 4y agoIt's a well-known method to uniformly sample the surface of an n-dimensional sphere.
- Someone 4y agoI guess/think you misread the “standard normal” part in that sentence as “uniform”.
- deleted 4y ago[deleted]
- 6gvONxR4sf7o 4y agoThe logic is that independent standard normals on each axis make up the multivariate standard normal, and the multivariate standard normal is rotationally invariant and therefore has the same density at any angle.