just another diary

Thursday, December 17, 2009

Random rays.

Trying to generate random rays, I have got a problem.
Basically I had few ways to get a 'random' vector or in other words a random point on the surface of the unit sphere.
  1. The first way was to generate random points in unit cube discarding points that are out of the unit sphere.
    But it can take much time, because of points that are just being generated outside of the sphere and are being discarded just wasting time.
  2. The second way was to get random 'rho' and 'phi' for polar coordinates.
    The problem was, I had non-uniform probability of points of the sphere due to 'cylindrical coords. ->spherical coords. transformation' (closer to poles - higher probability).
  3. The third way was to just normalize the random point in the unit cube to the unit sphere.
    The problem here was, I had non-uniform probability distribution (it's pretty clear, why).
  4. There is another way to do it, unimplemented though. It is as follows:
    "My idea is this: I want to create a tetrahedron, normalize its vertexes, split each face (triangle) with the point in the middle, normalize it and repeat recursively until I have enough points. Then I "distort" these points a little bit if any. Then I normalize them again. That's it."

Finally, I have found more or less easy way to generate random rays without mentioned drawbacks, thanks to David Norman and WolframMathWorld.
It is a method marked with formulas (6), (7) and (8) in the article on the last link. It is pretty close to 'my' first method but is has z calculated not via angle, but directly. It fixes the problem with non-uniformity.

And regarding the 4th described method: I will try to implement it later, I am pretty satisfied with results received from the Stackoverflow.

No comments:

Post a Comment

My Blog List

Powered by Blogger.