Fast uniformly distributed random points on the surface of a unit hemisphere

前端 未结 7 1051
天涯浪人
天涯浪人 2020-12-15 18:26

I am trying to generate uniform random points on the surface of a unit sphere for a Monte Carlo ray tracing program. When I say uniform I mean the points are uniformly distr

7条回答
  •  旧巷少年郎
    2020-12-15 18:46

    1st try (wrong)

    point=[rand(-1,1),rand(-1,1),rand(-1,1)];
    len = length_of_vector(point);
    

    EDITED:

    What about?

    while(1)
     point=[rand(-1,1),rand(-1,1),rand(-1,1)];
     len = length_of_vector(point);
     if( len > 1 )
         continue;
     point = point / len
         break
    

    Acception is here approx 0.4. Than mean that you will reject 60% of solutions.

提交回复
热议问题