本文介绍了如何用它们之间的距离生成随机位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个具有6个距离元素的向量,如下:

  D = [10.5 44.8 30.01 37.2 23.4 49.1]。 

我试图在200米的圆圈内创建一个给定距离的随机对位置。请注意,通过使用(b - a)。* rand(6,1)+ a ,与 a = 10 b = 50 。我不知道如何根据给定的距离生成随机对。



任何人都可以帮助我创建这种场景吗?

解决方案

这是对


Assume that I have a vector with 6 distance elements as

D = [10.5 44.8 30.01 37.2 23.4 49.1].

I'm trying to create random pair positions of a given distances, inside a 200 meters circle. Note that the distance D created by using (b - a).*rand(6,1) + a, with a = 10 and b = 50 in Matlab. I do not know how to generate the random pairs with given the distances.

Could anybody help me in generating this kind of scenario?

解决方案

This is an improvement to Alessiox's answer. It follows same logic, first generate a set of points ([X1 Y1]) that have at least distance D from the main circle border, then generate the second set of points ([X2 Y2]) that have exact distance D from the first set.

cx = 50; cy = -50; cr = 200;
D = [10.5 44.8 30.01 37.2 23.4 49.1]';
n = numel(D);

R1 = rand(n, 1) .* (cr - D);
T1 = rand(n, 1) * 2 * pi;
X1 = cx+R1.*cos(T1);
Y1 = cy+R1.*sin(T1);

T2 = rand(n, 1) * 2 * pi;
X2 = X1+D.*cos(T2);
Y2 = Y1+D.*sin(T2);

这篇关于如何用它们之间的距离生成随机位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 05:51