vendredi 21 septembre 2018

Random non overlapping coordinates of points

I am trying to create a function in Rust that will output a vector of length n, with random x,y coordinates of type f64. Every point with such coordinate must have a minimum distance "d" from each other. I am trying to use thread_rng() function but I am stuck. Should I use a specific distribution or add some filter or condition to achieve that?

pub fn apply_random_pos(n: usize, min_distance: f64) -> Vec<(f64, f64)>
{

  let mut rng = thread_rng();
  let mut x: f64;
  let mut y: f64;

  let mut positions: Vec<(f64, f64)> = Vec::with_capacity(n);

  positions = thread_rng().sample_iter(&Standard).take(n)
                 .collect::<Vec<(f64, f64)>>();

  positions   
}




Aucun commentaire:

Enregistrer un commentaire