资源简介
这是山东大学可视化课程的一个项目,用MATLAB实现的力导向图算法,请不要随意更改代码中的参数和数据集
代码片段和文件信息
DATA = int32(xlsread(‘bus685.xlsx‘1‘A1:B1282‘))+1;
position =xlsread(‘position.xlsx‘1‘A1:B685‘);
K_r = 0.1;
K_s = 0.025;
L = 2;
delta_t = 10;
MaxLength =8;
tic
for k = 1:100
force = zeros(6852);
for m = 2:684
for n = m+1:685
dx = position(n1)-position(m1);
dy = position(n2)-position(m2);
if dx~=0 || dy~=0
dist2 = dx^2+dy^2;
dist = sqrt(dist2);
f = K_r/dist2;
fx = f*dx/dist;
fy = f*dy/dist;
force(m1) = force(m1)-fx;
force(m2) = force(m2)-fy;
force(n1) = force(n1)+fx;
force(n2) = force(n2)+fy;
end
end
end
for m = 2:685
ne=find(DATA(:1)==m);
for n = 1:length(ne)
dx = position(DATA(ne(n)2)1)-position(m1);
dy = position(DATA(ne(n)2)2)-position(m2);
if dx~=0||dy~=0
dist = sqrt(dx^2+dy^2);
f = K_s*(dist-L);
fx = f*dx/dist;
fy = f*dy/dist;
force(m1) = force(m1)+fx;
force(m2) = force(m2)+fy;
force(DATA(ne(n)2)1) = force(DATA(ne(n)2)1)-fx;
force(DATA(ne(n)2)2) = force(DATA(ne(n)2)2)-fy;
end
end
end
for i = 2:685
dx = delta_t*force(i1);
dy = delta_t*force(i2);
displacement = dx^2+dy^2;
if(displacement>MaxLength)
s = sqrt(MaxLength/displacement);
dx = s*dx;
dy = s*dy;
end
position(i1) = position(i1)+dx;
position(i2) = position(i2)+dy;
end
end
toc
for i = 1:1282
s = DATA(i1);
d = DATA(i2);
x = [position(s1);position(d1)];
y = [position(s2);position(d2)];
plot(xy‘o-b‘);
hold on;
end
sum = 0;
for j = 1:685
sum = sum+abs(force(j1))+abs(force(j2));
end
sum
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 26927 2017-10-29 19:14 bus685.xlsx
文件 1843 2017-11-03 10:55 VIS.m
评论
共有 条评论