-
Notifications
You must be signed in to change notification settings - Fork 3
/
side_priority.m
56 lines (52 loc) · 2.04 KB
/
side_priority.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
%side priority - average sidemost 4 neighbors (with dead zone)
temp = zeros(1,N-1);
for i = 1:N
index = 0;
diff_side = abs(abs(dp.theta(i,:)) - 90);
%remove self
for j = 1:N
if j ~= i
index = index + 1;
temp(index) = diff_side(j);
end
end
diff_side = temp;
sorted = sort(diff_side);
%sorted = sort(abs(abs(dp.theta(i,:)) - 90));
index = 0;
min_i = 1; %index into sorted array that yields sidemost dp.theta
for k = 1:N-1
for j = 1:N
%remove dead zone, searching zone, and self, and limit to 4
if index < 4 && j ~= i && abs(dp.theta(i,j)) < (180 - w)...
&& d(i,j) < r3 && abs(abs(dp.theta(i,j)) - 90) == sorted(min_i)
index = index + 1;
side4(index) = j;
%increment min index -> index of next sidemost dp.theta
min_i = min_i + 1;
end
% if index < 4 && k ~= i && abs(dp.theta(i,j)) < (180 - w)...
% && d(i,j) < r3 && abs(abs(dp.theta(i,j)) - 90) == sorted(k)
% side4(index + 1) = j;
% index = index + 1;
% end
end
end
if index > 0 %at least 1 neighbor visible
beta_avg = npi2pi(sum(beta(i,side4(1:index)))/index);
%add randomness (normal distribution)
sigma = 15; %standard deviation = 15 degrees
alpha = beta_avg + sigma*randn(1);
%calculate velocity vector
v.theta(i) = npi2pi(v.theta(i) + alpha);
avg_mag = mean(v.mag(side4(1:index)));
%add randomness (normal distribution)
sigma = .2; %standard deviation = .2 (need bio basis for this)
new_vmag(i) = avg_mag + sigma*randn(1);
else %no neighbors in sight -> searching
beta_avg = npi2pi(360*rand);
alpha = beta_avg; %no need to add normal dist.
v.theta(i) = npi2pi(v.theta(i) + alpha);
new_vmag(i) = gamrnd(4,1/3.3,1,1); %random on gamma if no neighbors
end
end