3 ms·
That is actually a really nice question, essentially it boils down to the same trouble as he described with the taking each coordinate between -1 and 1 and norm
by adament 9y ago
That is actually a really nice question, essentially it boils down to the same trouble as he described with the taking each coordinate between -1 and 1 and normalizing, in that you get certain preferred directions and not the uniform distribution on the sphere. In your case you get that each of the circles described by your first angle are equally probable. But when you look at a sphere and trace them out, they have different lengths, hence they should have different probabilities. The most extreme case is that the pole (a single direction) has just as high a probability as the entire equator combined.
Just for prudence sake; one way of seeing why the normalization of n independent gaussian draws works. Is that the multivariate normal distribution in n-dimensions with independent coordinates is rotationally symmetric. One can visualize this in 2 dimensions by making a graph of the probability density and seeing it is invariant under rotations of the plane. This generalizes to higher dimensions. This is exactly the property that any direction is equally likely.
- x1798DE 9y agoAh, this makes a lot of sense. I tooled around a bit plotting some distributions with matplotlib after I posted my comment and indeed found that drawing random angles was clustered around the poles. From your explanation, now it seems almost obvious that it would be that way.
- bb88 9y agoYeah, I hit a similar problem way back in college when trying to generate random light rays from a point. I remember it being a tricky problem and hard to model without some kind of software to figure out if the randomness was correct.
- tzs 9y agoSuppose you are in a spaceship, and you want to pick a random direction to travel. You want to do so with at most one pitch change, one roll change, and one yaw change. One could of course do this by picking the direction first, and then calculating the necessary pitch/roll/yaw changes to point that way, but I wonder if there is a good way to it without selecting the direction first? In other words, can you do it just by using your random numbers to pick pitch, roll, and yaw changes, assuming you only have the common random number generator distributions available. First thing that comes to mind would be to do a random pitch change in [-pi, pi) then a random yaw change in [-pi, pi), but I think that is still going to be non-uniform. It doesn't have the same problem as the lat/long approach (because both pitch and yaw move on great circles, so you don't have anything like the variable length latitude line problem), but it still favors some points. Including a random roll step in there changes it from two favored points to a favored great circle (I think...visualizing this is hurting my brain), but I suspect that no finite sequence of pitch, roll, yaw random steps determined by independent random numbers with distributions that are not changing based on prior selections can erase biases that stem from the fact that this approach is starting with the ship pointing at a particular point and having a particular initial orientation.
- rzzzt 9y ago"Hot spots" of directions appear because the more your spacecraft pitches "up" or "down", the less contribution yaw changes make on the final result. At the extremes, the entire range of yaw values is effectively wasted on rolling: https://en.wikipedia.org/wiki/Gimbal_lock#In_three_dimensions https://en.wikipedia.org/wiki/Gimbal_lock#In_three_dimension... gattr suggests in another comment to look for clues around global illumination methods on how to solve this problem; his reference has the equations for picking polar coordinates from two random numbers generated from a [0..1] uniform distribution in section IV. B.