pub fn sample_sphere_surface(
dim: usize,
n: usize,
radius: f64,
positive: bool,
) -> Result<Vec<Vec<f64>>>Expand description
Samples n points uniformly from the surface of the dim-dimensional
sphere of the given radius, centered at the origin, using the thread’s
default random number generator.
With positive set, the points are restricted to the positive orthant
(all coordinates non-negative). Each returned point has dim
coordinates and Euclidean norm radius. With positive and
radius <= 1 they are valid latent positions for
Graph::dot_product_game (put them in
the columns of its matrix).
Binds igraph_rng_sample_sphere_surface.
Time complexity: O(n · dim).
§Errors
ErrorKind::InvalidValue if
dim < 2, or radius is not positive and finite.
§Examples
use igraph::{misc, prelude::*};
rng::seed(42)?;
for p in misc::sample_sphere_surface(3, 10, 2.0, true)? {
let norm = p.iter().map(|x| x * x).sum::<f64>().sqrt();
assert!((norm - 2.0).abs() < 1e-9);
assert!(p.iter().all(|&x| x >= 0.0));
}