Re:Uniformly Sample Points in a Disk
by onedognight on Thursday May 26, 2022 @01:38AM
(#31515018)
Rejection sampling doesn’t need sin/cos.
What costs more, generating a random number and maybe a second or a random number and a sin/cos? This sounds very platform dependent.
Note that when generating random points in the 4-ball (i.e. a quaternion)? The ball takes up a much smaller percentage of the space in the hypercube compared to the disk in a square, so rejections sampling can take many iterations.
> What costs more, generating a random number and maybe a second or a random number and a sin/cos
You’re adding a very unpredictable loop branch and a bunch of data dependencies doing that. For GPUs (and maybe even CPUs), the sqrt way is almost certainly faster.
If you have ALUs to spare, you can generate multiple points in parallel, say 4, and it is likely that at least one is inside the disk and you can select it branchlessly. Then you only need to loop in the very very rare case.
Re:Uniformly Sample Points in a Disk
by thomasahle on Thursday May 26, 2022 @01:36PM
(#31521178)
Just saying it's not clear and one would have to benchmark to find out.
Re:Uniformly Sample Points in a Disk
by jeffparsons on Wednesday May 25, 2022 @09:27PM
(#31513158)
Spot on. A lot of graphics people in the thread point this out. (I am not a graphics person — I occasionally tinker, but mostly just appreciate it from a distance.)
Assmuning this is a graphics operation running on a GPU. Taking the sqrt is pretty optimized, and having a branch for every point to be sampled is not fun.