News for hackers. Stuff that matters.
Re:Uniformly Sample Points in a Disk by toxicFork on Wednesday May 25, 2022 @10:11PM (#31513441)
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.

Re:Uniformly Sample Points in a Disk by eru on Thursday May 26, 2022 @01:58AM (#31515145)
And 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.)

Re:Uniformly Sample Points in a Disk by toxicFork on Thursday May 26, 2022 @03:02AM (#31515510)
> 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.

Re:Uniformly Sample Points in a Disk by 6gvONxR4sf7o on Thursday May 26, 2022 @10:43AM (#31518937)
The 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.
Re:Uniformly Sample Points in a Disk by whyever on Thursday May 26, 2022 @06:59AM (#31516896)
It's a well-known method to uniformly sample the surface of an n-dimensional sphere.
Re:Uniformly Sample Points in a Disk by Someone on Thursday May 26, 2022 @06:59AM (#31516897)
I guess/think you misread the “standard normal” part in that sentence as “uniform”.
Re:Uniformly Sample Points in a Disk by keefe8 on Thursday May 26, 2022 @05:16AM (#31516267)
It appears to be uniform. I tested empirically in Python: https://pastebin.com/raw/ca03uywJ
Re:Uniformly Sample Points in a Disk by toxicFork on Thursday May 26, 2022 @09:48AM (#31518286)
Re:Uniformly Sample Points in a Disk by keefe8 on Saturday May 28, 2022 @04:08AM (#31538520)
I meant to show the output of my code, but Pasteboard was down at the time: https://gcdnb.pbrd.co/images/f8bgGZMW3deq.png?o=1
Re:Uniformly Sample Points in a Disk by Malipeddi on Thursday May 26, 2022 @10:35AM (#31518817)
Normal distribution is not the same as uniform distribution. I edited in a normal distribution sampler in your codepen example.

https://pastebin.com/raw/CP4yNRE9

Re:Uniformly Sample Points in a Disk by toxicFork on Thursday May 26, 2022 @11:09AM (#31519278)
I see, thanks!
Re:Uniformly Sample Points in a Disk by eru on Thursday May 26, 2022 @11:41PM (#31525805)
Btw, the following two are equivalent (in JavaScript syntax):

    var a = Math.max(Math.random(), Math.random());
    var b = Math.sqrt(Math.random());
Re:Uniformly Sample Points in a Disk by toxicFork on Friday May 27, 2022 @01:12AM (#31526207)
Curious, how come? Does it become a statistical thing?
Re:Uniformly Sample Points in a Disk by eru on Monday May 30, 2022 @04:11AM (#31556619)
Well, 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