资源简介
改良的Boid集群运动模型,可以运行能够跑出来,仅供参考。
代码片段和文件信息
pos=cell(130);
for i=1:30
pos{i}=[rand(11)*10rand(11)*10rand(11)*10]
end
x=zeros(130);
y=zeros(130);
z=zeros(130);
v=0.1;
direct1=cell(130);
direct2=cell(130);
direct3=cell(130);
direct4=cell(130);
direct5=cell(130);
direct6=cell(130);
direct7=cell(130);
direct8=cell(130);
cons=zeros(130);
for i=1:30
direct1{i}=[rand(11)*10rand(11)*10rand(11)*10]-pos{i};
direct2{i}=zeros(13);
direct3{i}=zeros(13);
direct4{i}=zeros(13);
end
for t=1:1000
for i=1:30
m=0;
n=0;
k=0;
l=[000];
direct7{i}=zeros(13);
direct8{i}=zeros(13);
for j=1:30
if j==i
continue
else
for r=1:30
direct7{i}=(direct7{i}+pos{r}-pos{i})./r;
direct8{i}=(direct8{i}+direct1{r})./r;
end
if (norm(pos{i}-pos{j})<=5)&&(norm(pos{i}-pos{j})>=0.1)
m=m+1;
k=k+norm(direct1{j});
l=l+direct1{j};
direct2{i}=(direct2{i}+(pos{j}-pos{i}))./m;
direct3{i}=(direct3{i}+direct1{j})./m;
cons(i)=norm(l)/k;
elseif norm(pos{i}-pos{j})<0.1;
n=n+1;
direct4{i}=(direct2{i}+(pos{i}-pos{j}))./n;
end
end
end
if (pos{i}(1)>=10)||(pos{i}(2)>=10)||(pos{i}(1)<=0)||(pos{i}(2)<=0)||(pos{i}(3)>=10)||(pos{i}(3)<=0)
direct1{i}=direct1{i}*(-1);
else
direct1{i}=0.1*direct1{i}+0.1*direct2{i}+0.1*direct3{i}+0.1*direct4{i}+0.3*direct7{i}+0.3*direct8{i};
end
pos{i}=pos{i}+direct1{i}/norm(direct1{i})*v*exp(5*(cons(i)-1));
end
for i=1:30
x(i)=pos{i}(1);
y(i)=pos{i}(2);
z(i)=pos{i}(3);
end
plot3(xyz‘^‘)
axis([0 10 0 10 0 10]‘square‘‘manual‘)
grid on;
pause(0.01)
end
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-04-16 18:28 Boid模型代码\
文件 2028 2018-04-16 18:26 Boid模型代码\Unti
文件 3590 2018-04-16 18:27 Boid模型代码\Unti
- 上一篇:直方图均衡化 matlab 代码
- 下一篇:地震记录合成
评论
共有 条评论