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

前端 未结 7 1036
天涯浪人
天涯浪人 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 19:04

    If you take a horizontal slice of the unit sphere, of height h, its surface area is just 2 pi h. (This is how Archimedes calculated the surface area of a sphere.) So the z-coordinate is uniformly distributed in [0,1]:

    azimuthal = 2*PI*dsfmt_genrand_close_open(&dsfmtt);
    osRay.c._z = dsfmt_genrand_close_open(&dsfmtt);
    
    xyproj = sqrt(1 - osRay.c._z*osRay.c._z);
    osRay.c._x = xyproj*cos(azimuthal); 
    osRay.c._y = xyproj*sin(azimuthal);
    

    Also you might be able to save some time by calculating cos(azimuthal) and sin(azimuthal) together -- see this stackoverflow question for discussion.

    Edited to add: OK, I see now that this is just a slight tweak of your third method. But it cuts out a step.

    0 讨论(0)
提交回复
热议问题