-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckcollide.m
90 lines (78 loc) · 2.43 KB
/
checkcollide.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
function [ collide ] = checkcollide(E)
len = length(E);
collide = zeros(len,len,4);
% vect = [];
A = zeros(len,2);
B = zeros(len,2);
C = zeros(len,2);
for i =1:len
% disp('startnow')
% disp(i)
% disp(A)
% disp(E(i).Ar2')
A(i,:)=E(i).Ar2';
B(i,:)=E(i).Br2';
C(i,:)=E(i).center2';
end
AA = A*A';
AB = A*B';
AC = A*C';
BB = B*B';
BC = B*C';
tol = 1.0000;
for i = 1:len
for j = 1:len
a=0;
b=0;
c=0;
d=0;
if i == j
continue
end
if ((AC(i,j)-AB(i,j)-AA(i,j))/AA(i,i)) <= ((AC(i,i)/AA(i,i)) + tol)...
&& ((AC(i,j)-AB(i,j)-AA(i,j))/AA(i,i)) >= ((AC(i,i)/AA(i,i)) - tol)
a=a+1;
end
if ((BC(i,j)-BB(i,j)-AB(j,i))/BB(i,i)) <= ((BC(i,i)/BB(i,i)) + tol)...
&& ((BC(i,j)-BB(i,j)-AB(j,i))/BB(i,i)) >= ((BC(i,i)/BB(i,i)) - tol)
a=a+1;
if a ==2
collide(i,j,3)=1;
end
end
if ((AC(i,j)+AB(i,j)-AA(i,j))/AA(i,i)) <= ((AC(i,i)/AA(i,i)) + tol)...
&& ((AC(i,j)+AB(i,j)-AA(i,j))/AA(i,i)) >= ((AC(i,i)/AA(i,i)) - tol)
b=b+1;
end
if ((BC(i,j)+BB(i,j)-AB(j,i))/BB(i,i)) <= ((BC(i,i)/BB(i,i)) + tol)...
&& ((BC(i,j)+BB(i,j)-AB(j,i))/BB(i,i)) >= ((BC(i,i)/BB(i,i)) - tol)
b=b+1;
if b ==2
collide(i,j,2)=1;
end
end
if ((AC(i,j)+AB(i,j)+AA(i,j))/AA(i,i)) <= ((AC(i,i)/AA(i,i)) + tol)...
&& ((AC(i,j)+AB(i,j)+AA(i,j))/AA(i,i)) >= ((AC(i,i)/AA(i,i)) - tol)
c=c+1;
end
if ((BC(i,j)+BB(i,j)+AB(j,i))/BB(i,i)) <= ((BC(i,i)/BB(i,i)) + tol)...
&& ((BC(i,j)+BB(i,j)+AB(j,i))/BB(i,i)) >= ((BC(i,i)/BB(i,i)) - tol)
c=c+1;
if c ==2
collide(i,j,1)=1;
end
end
if ((AC(i,j)-AB(i,j)+AA(i,j))/AA(i,i)) < ((AC(i,i)/AA(i,i)) + tol)...
&& ((AC(i,j)-AB(i,j)+AA(i,j))/AA(i,i)) > ((AC(i,i)/AA(i,i)) - tol)
d=d+1;
end
if ((BC(i,j)-BB(i,j)+AB(j,i))/BB(i,i)) < ((BC(i,i)/BB(i,i)) + tol)...
&& ((BC(i,j)-BB(i,j)+AB(j,i))/BB(i,i)) > ((BC(i,i)/BB(i,i)) - tol)
d=d+1;
if d ==2
collide(i,j,4)=1;
end
end
end
end
end