How can we provide minimum distance i.e. 20 between each random generated node?

4 vues (au cours des 30 derniers jours)
No_of_clusters = 25
no_sensor_box = 8
for i=1:no_of_clusters
for j=1:no_sensor_box
Xloc(s)=randi([x_loc1(i)+1,x_loc2(i)-1],1,1);
Yloc(s)=randi(([y_loc1(i)+1,y_loc3(i)]-1),1,1);
s=s+1;
end
end
This code generates nodes at some random locations, but I want the minimum distance (i.e.=20) between two nodes that means the minimum distance between each node are not less than 20. How to provide minimum distance between two nodes in this?
  1 commentaire
Torsten
Torsten le 8 Nov 2017
How is the distance between two nodes s1 and s2 defined ?
d(s1,s2) = sqrt((Xloc(s1)-Xloc(s2))^2+(Yloc(s1)-Yloc(s2))^2)
?
Best wishes
Torsten.

Connectez-vous pour commenter.

Réponse acceptée

John D'Errico
John D'Errico le 8 Nov 2017
Um, there isn't a way. Well, not to do it by one simple call. You will need to write code.
Given the set of nodes already generated, just generate a new random point, subject to no constraints. Use a uniform random generator, like rand. Compute the distance to every other node. This is trivial of course.
Then if the new node is too close to any other node, toss it away, into the bit bucket. Repeat until you find a new node that is acceptable.
Eventually, you will find that it becomes really difficult to choose new nodes. You are done then.
Sorry, but that is what you will need to do. Could you do it more efficiently? Well, yes. I suppose in theory, you could do so. You would need to build a triangulation of the region that would define the region where new nodes may be validly chosen, because they are sufficiently faraway from any existing node. Then choose a new point uniformly from the valid domain. Given the new node, since it was in the valid set, exclude all portions of the existing triangulation that are within a radius of r from the new node, reducing the valid set.
This may become somewhat computationally intensive to do the exclusion, because that triangulation may become a rather messy one. But it would get smaller all the time too.
So, COULD you solve your problem without using a simpler rejection scheme? Yes. But not worth the effort unless you really understand how to work with triangulations of the plane. Just use the first scheme I proposed.

Plus de réponses (1)

Torsten
Torsten le 8 Nov 2017
Modifié(e) : Jan le 10 Mai 2019
I think Jan Simon's answer will at least partially solve your problem:
Best wishes
Torsten.

Catégories

En savoir plus sur Triangulation Representation dans Help Center et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by