-
Notifications
You must be signed in to change notification settings - Fork 0
/
repel.m
53 lines (35 loc) · 1.01 KB
/
repel.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
function repforce = repel(P,cd, mu)
nPoints = length(P);
L = P(1:ceil(nPoints/2), :);
M = P(nPoints - floor(nPoints/2):nPoints, :);
repel1 = zeros(length(L), 2);
force = zeros(nPoints,2);
for i = 1:length(L(:,1))
FL = [0 0];
for j = 1:length(M)
fj = sqrt(sum(((L(i,:)-M(j,:)).^2)))/cd;
pickone = max([0, 1-fj]);
fx = pickone*((L(i,1)-M(j,1))/cd);
fy = pickone*((L(i,2)-M(j,2))/cd);
fxy = [fx fy];
FL = FL + fxy;
end
repel1(i,:) = FL;
end
repel2 = zeros(length(L), 2);
for i = 1:length(M)
FL = [0 0];
for j = 1:length(L(:,1))
fj = sqrt(sum(((M(i, :)-L(j,:)).^2)))/cd;
pickone = max([0, 1-fj]);
fx = pickone*((M(i,1)-L(j,1))/cd);
fy = pickone*((M(i,2)-L(j,2))/cd);
fxy = [fx fy];
FL = FL + fxy;
end
repel2(i,:) = FL;
end
force(1:ceil(nPoints/2),:) = repel1;
force(nPoints-50:nPoints,:) = repel2(end-50:end,:);
repforce = mu*force;
end