-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathFindVO.m
71 lines (58 loc) · 1.54 KB
/
FindVO.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 ] = FindVO( Pos_A, Pos_B, r_A, r_B, v_Abest, v_B)
% This function is used for judging the uav will have a collsion or not
ag2=v_Abest(2)-v_B(2);
ag1=v_Abest(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