how to generate the node with the distance of R from other nodes

2 次查看(过去 30 天)
i want to generate random nodes with the distance of radius R from another nodes in environment how can i make a command?
  2 个评论
Walter Roberson
Walter Roberson 2015-5-13
Is each of them required to be distance R from each other? Or only distance R from the first one? How many dimensions are you working in?
amina shafanejad
amina shafanejad 2015-5-13
yes it need to be distance R from each other im working dimension 10 by 10,can u help me with that

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2015-5-13
On any two-dimensional surface, the maximum number of points that can all be distance R from each other is 3, forming an equilateral triangle. In any three-dimensional space, the maximum number of points that call all be distance R from each other is 4, forming a regular tetrahedran. In any space with N dimensions, (N+1) points can be an equal distance from each other, forming the N-dimensional hyperspace analog of the regular tetrahedron.
To find three equidistant points on a plane, let (x1, y1) be x, y coordinates randomly chosen from anywhere on the plane. Then pick a random angle, theta, in the range 0 to 2*pi,
rang = rand(0,1)*2*pi;
and use that with distance R to construct a vector offset:
[deltax, deltay] = pol2cart(rang, R);
add this to (x1, y1) to get the coordinates of your second point:
x2 = x1 + deltax;
y2 = y1 + deltay;
Once you have done this, there are only two possible positions for the third point. If you view (x1,y1) -> (x2,y2) as a vector, the third point must be either to the "left" or to the "right" of the vector. You can choose which randomly. But once you know which side, the position is completely fixed.
An easier approach is to find the coordinates of an equilateral triangle starting at (0,0), one vertex at (0,1), and the third vertex to be determined. A quick calculation (see e.g. this) shows that the coordinates must be (0,0), (0,1), (1/2, sqrt(3)/2). Multiply all of those by R to scale up to sides of length R. Now rotate that around the origin by a random angle. Choose a random x and y offset and add them to the rotated values. The result will be a randomly placed equilateral triangle with sides of length R, and thus will be 3 randomly placed nodes on the plane.
I repeat for emphasis: on an X-Y plane, there are at most 3 points that are the same distance apart from each other. Trying to generate more will always fail.

类别

Help CenterFile Exchange 中查找有关 Graph and Network Algorithms 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by