-
Notifications
You must be signed in to change notification settings - Fork 827
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Listing 37: Incorrectly generating random unit vector #697
Comments
This is related to #696 |
See https://mathworld.wolfram.com/SpherePointPicking.html for the derivation of the |
Reading my own advice... don't to that either it has a similar problem. But I'm assuming wolfram would have a much better fix. :) |
No fix to the function is needed. The current function is identical to the approach illustrated in Wolfram, though the variable names are different. |
Hmmm. Now I'm doubting myself. I think you may be right. Investigating. Specifically, for equations 6-8 on the Wolfram page, |
Took a while to get through my thick skull. Turns out I added this alternate algorithm 2019-10-21 (one year ago), and yes, misunderstood what u meant above. The original form used |
I added an alternate formula for uniformly-distributed points on a unit sphere for this function. It's presented in https://mathworld.wolfram.com/SpherePointPicking.html, equations 6-8. Unfortunately, I misinterpreted "u in [-1, 1]" to be equivalent to `u = random_double(-1,1)`. However, you're supposed to pick u = cos(phi) to be uniformly distributed. I replaced this body with the original one, just generating a unit point _in_ the unit sphere, and normalizing the result. Resolves #697
Maybe I'm reading this incorrectly but what the code does doesn't seem to match the function name. The current code appears to do a uniform distribution on cylinder and then stretch to a sphere. Doesn't that raise the probability of points near the poles?
I was expecting something more like this:
The text was updated successfully, but these errors were encountered: