我有一个表现为附着生物分布的表面(随机生成),但是一些点会在期望区域之外生成。我希望任何在表面之外生成的点能够出现在另一侧。
这样,如果你将这个表面想象成一个“瓷砖”,当无限个瓷砖铺设时,就不会出现跳跃或间隙,它是周期性的。
这样,如果你将这个表面想象成一个“瓷砖”,当无限个瓷砖铺设时,就不会出现跳跃或间隙,它是周期性的。
clear
n_gaussians=20; % number of barnacles
gaussians=0;
sigma=1; % std deviation
mindist=0.8*sigma; % if distance is smaller than this gaussians "collide" and are not plotted
height=0.3; % height of the barnacle
[x,y]= meshgrid(-5:0.05:5,-5:0.05:5);
used=[];
Z=zeros(size(x));
while gaussians<n_gaussians
xm=(rand(1)-0.5)*10;
ym=(rand(1)-0.5)*10;
notvalid=0;
for ii=1:size(used,2)
% if we are too close to any point.
if norm([xm-used(1,ii),ym-used(2,ii)])<mindist
notvalid=1; % do not add this gauusian
end
end
if notvalid
continue
end
used(:,end+1)=[xm;ym];
Zaux = height/sigma*exp(-5*((x-xm).^2+(y-ym).^2)/sigma.^2)-0.1;
Zaux(Zaux<0)=0;
Z=Z+Zaux;
gaussians=gaussians+1;
end
surf(x,y,Z);
axis equal
shading interp
这张图片希望能够解释所需内容:
我还需要保留间距,因此,如果xm,ym在绘图的另一侧的高斯分布距离范围内,它们需要被折扣。我已经尝试过让它工作,但似乎找不到方法。任何帮助将不胜感激!