Random planar angle by one-dimensional rejection sampling
Source:R/cone_sampling.R
generate_planar_angle_rejection.RdDraws a single random planar angle \(\theta \in [0, \theta_0]\) from the distribution required to produce uniform sampling on a spherical cap of half-angle \(\theta_0\) in dimension \(n\), using one-dimensional rejection sampling with log-domain comparisons. Numerically stable in high dimensions where the inverse-transform variant underflows.
Details
The probability density function of \(\theta\) is: $$f_\theta(\theta) = \frac{s_{n-1}}{s_n \Theta(\theta_0)} \sin^{n-2}(\theta)$$ This function uses one-dimensional rejection sampling with log transformations to avoid floating-point underflow. The acceptance condition is: $$\log(U) < (n-2)[\log(\sin\theta) - \log(\sin\min(\theta_0, \pi/2))]$$ where \(U \sim \text{Uniform}(0,1)\).
The average number of rejections is approximately linear in n, maintaining the O(n) complexity of the overall algorithm.
References
Arun, I., & Venkatapathi, M. (2025). An O(n) algorithm for generating uniform random vectors in n-dimensional cones. Sankhya A, 87(2), 327-348. doi:10.1007/s13171-025-00387-9
See also
generate_planar_angle_inverse for the inverse-transform
alternative; rejection_cost for the expected number of
rejections in the rejection-based cone sampler;
generate_cone_sample for the downstream cone sampler.