Let's say I want a particle to move randomly in 3d space. I have to do the following
1) Generate random theta direction
2) Generate random phi direction
Well, this should be as simple as generating a random number between 0 and 1 and multiplying that by 2*pi and then repeating this for pi. That doesn't work so well. If we do this, we don't get an even 3d distribution of movement. Instead, you get mostly movement towards the poles.
Here is a solution
1) Generate random phi direction (2*pi*random)
2) Generate random cos(theta) (2*random - 1)
3) Generate sin(theta) = sqrt(1-(costheta)^2)
Does anyone know why, from first principles, it has to be done this way.
1) Generate random theta direction
2) Generate random phi direction
Well, this should be as simple as generating a random number between 0 and 1 and multiplying that by 2*pi and then repeating this for pi. That doesn't work so well. If we do this, we don't get an even 3d distribution of movement. Instead, you get mostly movement towards the poles.
Here is a solution
1) Generate random phi direction (2*pi*random)
2) Generate random cos(theta) (2*random - 1)
3) Generate sin(theta) = sqrt(1-(costheta)^2)
Does anyone know why, from first principles, it has to be done this way.