how to generate the node with the distance of R from other nodes
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
i want to generate random nodes with the distance of radius R from another nodes in environment how can i make a command?
2 Commenti
Walter Roberson
il 13 Mag 2015
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?
Risposte (1)
Walter Roberson
il 13 Mag 2015
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.
0 Commenti
Vedere anche
Categorie
Scopri di più su Graph and Network Algorithms in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!