I was playing around with writing a code for Montecarlo integration of a function defined in spherical coordinates. As a first simple rapid test I decided to write a test code to obtain the solid angle under an angle $\theta_m$. For two random number $u$ and $v$ in $[0,1)$. I generate a homogeneous random sampling of the spherical angle using

$$\phi=2\pi u$$

$$\theta = \arccos(1-2v)$$

For $N$ generated points, I have $M$ points for which $\theta < \theta_m$. My first idea was that since I have an homogeneous sampling I should have obtained the correct solid angle $\Omega=2 \pi (1-\cos (\theta_m))$ simply as $4\pi\times M/N$. Actually it looks like I the correct result comes out only if I use:

$$\Omega=\sum_{i=1}^M \frac{4\pi}{N} 2 \cos(\theta_i)$$

I can not see the reason why this should be correct. The probability distribution function in $\theta$ is $PDF=1/2 \sin(\theta)$ so I would rather expect I should normalize each point of the sum by this function but this doesn't work. What am I doing wrong and how could I justify the cosine? Many thanks!

  • $\begingroup$ How do you know your test was wrong? How large was $N$, what was $\theta_m$, and what was the standard error of the estimate $4\pi M/N$? $\endgroup$
    – whuber
    May 22, 2011 at 21:05

1 Answer 1


Your calculations are correct and you should get the right Monte Carlo estimate from your formula $4\pi M/N$ with the mapping $(u,v)\to(\phi,\theta)$ you presented. So I would guess it's an error in your code and not in your reasoning. You shouldn't need the cosine weighting factor. Perhaps if you show your code we can spot the error.

Also, on a related note, there's a really nice paper by James Arvo called Stratified Sampling of 2-Manifolds which explains how to construct an area-preserving mapping from the unit-square to a 2-manifold in general, but also specifically for a (hemi-)sphere.

  • $\begingroup$ Thank's for the answer and indeed the error was in the code. Everything looks fine now. $\endgroup$
    – astolfo
    May 23, 2011 at 8:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.