Sample point on a sphere with given radius
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(rng_t), | intent(inout) | :: | self | |||
| real(kind=dp), | intent(in) | :: | radius |
function sphere(self, radius) result(xyz) class(rng_t), intent(inout) :: self real(dp), intent(in) :: radius real(dp) :: rands(2), xyz(3) real(dp) :: sum_sq, tmp_sqrt ! Marsaglia method for uniform sampling on sphere do rands(1) = 2 * self%unif_01() - 1 rands(2) = 2 * self%unif_01() - 1 sum_sq = sum(rands**2) if (sum_sq <= 1) exit end do tmp_sqrt = sqrt(1 - sum_sq) xyz(1:2) = 2 * rands(1:2) * tmp_sqrt xyz(3) = 1 - 2 * sum_sq xyz = xyz * radius end function sphere