-
Notifications
You must be signed in to change notification settings - Fork 4
/
Feedback.m
71 lines (59 loc) · 1.56 KB
/
Feedback.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
function [ Result,alpha, beta, gamma ] = Feedback( Pos_A, Pos_B, r_A, r_B, v_Afinal, v_B)
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
ag2=v_Afinal(2)-v_B(2);
ag1=v_Afinal(1)-v_B(1);
gamma=atan2(ag2,ag1);
if gamma < 0
gamma=2*pi+gamma;% the angle of v_A -v_B
end
VOY=Pos_B(2)- Pos_A(2);
VOX=Pos_B(1)- Pos_A(1);
alpha=atan2(VOY,VOX);
if alpha < 0
alpha= 2*pi+alpha; % the angle between agent connection line and X axis
end
d=sqrt(VOX^2+VOY^2);
if d== r_B+r_B
if alpha >= 0 && alpha < pi/2
if (gamma >=0 && gamma < alpha+pi/2) || (gamma > alpha+3*pi/2 && gamma <2*pi)
Result=1;
else
Result=0;
end
elseif alpha >=pi/2 && alpha < (3*pi/2)
if gamma >alpha-pi/2 && gamma <alpha +pi/2
Result =1;
else
Result=0;
end
else
if (gamma>alpha- pi/2 && gamma <=2*pi) || (gamma >=0 && gamma <alpha-3*pi/2)
Result=1;
else
Result=0;
end
end
else
beta=asin((r_A+r_B)/d);
if (alpha-beta) <0
if (gamma >= 0 && gamma < (alpha+beta)) || (gamma > (alpha-beta +2*pi) && gamma <= 2*pi)
Result =1;
else
Result=0;
end
elseif (alpha+beta)> (2*pi)
if (gamma >= 0 && gamma < (alpha+beta-2*pi)) || (gamma > (alpha-beta) && gamma <= 2*pi)
Result =1;
else
Result=0;
end
else
if gamma > alpha-beta && gamma < alpha+beta
Result=1;
else
Result=0;
end
end
end
end