【发布时间】:2016-07-17 15:39:15
【问题描述】:
我正在尝试在500 米六边形内创建给定距离的N 随机点对(N = 50)。使用(dmax - dmin).*rand(N,1) + dmin创建的距离D,在Matlab中使用dmin = 10和dmax = 100。我知道第一个我必须生成一组点([x1 y1]),它们与主六边形边框的距离至少为D,然后生成第二组点([x2 y2]),与第一个点有精确的距离D放。但有时我在六边形之外遇到了第二个点的问题,因为如果在六边形边框上的第一个位置加上Ddisance,那么第二个位置在六边形之外(我的意思是我想在里面生成随机对位置六醇)。有人可以帮助我生成这种场景并解决问题吗?谢谢。
例如
R = 500; % hexagol radius
N = 50; % number pair positions
d_min = 10; % minimum distance
d_max = 100; % maximum distance
D = (d_max - d_min).*rand(N,1) + d_min; % randomly distance
X = [0,0]; % hexagol center
j=0;
while j < N
j=j+1;
theta(j)=2*pi*rand(1,1);
u= rand()+ rand();
if u < 1
r(j) = R * u;
else
r(j) = R * (2 - u);
end
% to create the first position
x1(j)=r(j)*cos(theta(j)) + X(1,1); % first x positions
y1(j)=r(j)*sin(theta(j)) + X(1,2); % first y positions
end
% to create the second position
x2(j) = x1(j) + D(j); % second x positions
y2(j) = y1(j) + D(j); % second y positions
【问题讨论】:
标签: matlab math geometry polygon