Uniform Unit Hemisphere

Sampling of points uniformly on the hemisphere. As with the disk, just randomly choosing two angles won’t give the desired result

function uniform_angular_hemisphere(){


    const u_1 = Math.random();
    const u_2 = Math.random();

    const theta = u_1 * Math.PI / 2.0;
    const phi = u_2 * 2.0 * Math.PI;

    return [theta,phi]
}

Now the result with a uniform area sampling of the upper hemisphere

function uniform_hemisphere(){

    const u_1 = Math.random();
    const u_2 = Math.random();

    // Math.acos(u_1) is also valid
    const theta = Math.acos(1.0 - u_1);
    const phi = u_2 * 2.0 * Math.PI;

    return [theta,phi]
}

Algorithm

Generate uniform points on the hemisphere

  1. Choose uniform numbers u1,u2u_1, u_2 in [0,1][0,1]
  2. Calculate θ=cos1(1u1)\theta = \cos^{-1}(1-u_1) or θ=cos1(u1)\theta = \cos^{-1}(u_1)
  3. Calculate ϕ=2πu2\phi = 2\pi u_2

Optionally convert to cartesian coordinates with:

x=sinθcosϕy=sinθsinϕz=cosθ\begin{aligned} x &= \sin\theta\cos\phi\\ y &= \sin\theta\sin\phi \\ z &= \cos\theta \end{aligned}

PDF Used In Monte Carlo Integration

p(ω)=12πp(\omega) = \frac{1}{2\pi}

p(θ,ϕ)=12πsinθp(\theta, \phi) = \frac{1}{2\pi}\sin\theta

Derivation

This is a special case of the general form discussed in the next section, but is shown as an example in more detail.

We want the pdf to be uniform over the unit hemisphere, so it will just be some constant for each solid angle p(ω)=c\Rightarrow p(\omega) = c

Ωp(ω)dω=Ωcdω=cΩdω=1\int_\Omega p(\omega)d\omega = \int_\Omega c d\omega = c \int_\Omega d\omega = 1

The easy way:

We know that the solid angle of the hemisphere is 2π2\pi . In general, for uniform sampling the pdf is just 1Vol(Ω)\frac{1}{\operatorname{Vol}(\Omega)} , where Vol\operatorname{Vol} is the volume of the sample space.

cΩdωc2π=1c=12πc\int_\Omega d\omega \Rightarrow c2\pi = 1 \Rightarrow c = \frac{1}{2\pi}

The complicated way:

Ωp(ω)dω=0π202πcsinθdθdϕ=c2π0π2sinθdθ=c2π[cosθ]0π2=c2π(cos0cosπ2)=c2π\begin{aligned} \int_\Omega p(\omega)d\omega &= \int_0^{\frac{\pi}{2}}\int_0^{2\pi}c\sin\theta d\theta d\phi \\ &= c 2\pi \int_0^{\frac{\pi}{2}}\sin\theta d\theta \\ &= c2\pi [-\cos\theta]_0^{\frac{\pi}{2}} \\ &= c2\pi (\cos 0 - \cos\frac{\pi}{2}) \\ &= c2\pi \end{aligned}

Therefore c2π=1c=12πc2\pi = 1 \Rightarrow c = \frac{1}{2\pi}

To convert to the angular representation, we have to add (The factor can be found similarly to the rr factor of the disk)

p(ω)=p(θ,ϕ)sinθp(\omega) = p(\theta,\phi)\sin\theta

Marginal And Conditional Densities:

pθ(θ)=02πp(θ,ϕ)sinθdϕ=02π12πsinθdϕ=12πsinθ2π=sinθp_\theta(\theta) = \int_0^{2\pi} p(\theta,\phi)\sin\theta d\phi = \int_0^{2\pi}\frac{1}{2\pi}\sin\theta d\phi = \frac{1}{2\pi}\sin\theta * 2\pi = \sin\theta

p(ϕθ)=p(θ,ϕ)pθ(θ)=sinθ2πsinθ=12πp(\phi \vert \theta) = \frac{p(\theta,\phi)}{p_\theta(\theta)} = \frac{\sin\theta}{2\pi\sin\theta} = \frac{1}{2\pi}

Compute CDFs

Pθ(θ)=0θsinθdθ=[cos(θ)]0θ=cos0cosθ=1cosθP_\theta(\theta) = \int_0^\theta \sin\theta' d\theta' = [-\cos(\theta')]_0^\theta = \cos 0 - \cos\theta = 1 - \cos\theta

P(ϕθ)=0ϕp(ϕθ)dϕ=0ϕ12πdϕ=ϕ2πP(\phi \vert \theta) = \int_0^\phi p(\phi' \vert \theta)d\phi' = \int_0^\phi \frac{1}{2\pi}d\phi' = \frac{\phi}{2\pi}

Invert CDFs

u1=Pθ(θ)=1cosθcosθ=1u1θ=cos1(1u1)u_1 = P_\theta(\theta) = 1 - \cos\theta \Rightarrow \cos\theta = 1 - u_1 \Rightarrow \theta = \cos^{-1}(1- u_1)

u2=P(ϕθ)=ϕθ2πu2=ϕu_2 = P(\phi \vert \theta) = \frac{\phi}{\theta} \Rightarrow 2\pi u_2 = \phi