MATLAB Answers


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

SHUAB KHAN さんによって質問されました 2017 年 11 月 8 日
最新アクティビティ Jan
さんによって 編集されました 2019 年 5 月 10 日
No_of_clusters = 25
no_sensor_box = 8
for i=1:no_of_clusters
for j=1:no_sensor_box
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 件のコメント

2017 年 11 月 8 日
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

サインイン to comment.


2 件の回答

回答者: John D'Errico
2017 年 11 月 8 日

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.

  0 件のコメント

サインイン to comment.

回答者: Torsten
2017 年 11 月 8 日
編集済み: Jan
2019 年 5 月 10 日

I think Jan Simon's answer will at least partially solve your problem:
Best wishes

  1 件のコメント

SHUAB KHAN 2017 年 11 月 9 日
Thanks Torsten, It'll help me a lot.

サインイン to comment.

Translated by