-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoxCollisionHandler.m
More file actions
32 lines (26 loc) · 1.45 KB
/
BoxCollisionHandler.m
File metadata and controls
32 lines (26 loc) · 1.45 KB
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
function states = BoxCollisionHandler(states, boxes)
% Locations of the walls of the boxes
left_wall = boxes.left_wall;
right_wall = boxes.right_wall;
top_wall = boxes.top_wall;
top_wall2 = boxes.top_wall2;
% Check if particle hit left wall of bottom box
indices = states(:,1) >= left_wall*0.99 & states(:, 1) <= left_wall*1.01 & states(:,2) < top_wall;
% if (states(indices,1) - left_wall < states(indices,1) - right_wall)
% states(indices, 1) = left_wall;
% else
% states(indices, 1) = right_wall;
% end
states(indices, 3) = -states(indices, 3);
% Check if particle hit the right wall of the bottom box
indices = states(:,1) >= right_wall*0.99 & states(:, 1) <= right_wall*1.01 & states(:,2) < top_wall;
states(indices, 3) = -states(indices, 3);
indices = states(:,2) <= top_wall*01.01 & states(:,1) > left_wall & states(:,1) < right_wall;
states(indices, 4) = -states(indices, 4);
indices = states(:,1) >= left_wall*0.99 & states(:, 1) <= left_wall*1.01 & states(:,2) > top_wall2;
states(indices, 3) = -states(indices, 3);
indices = states(:,1) >= right_wall*0.99 & states(:, 1) <= right_wall*1.01 & states(:,2) > top_wall2;
states(indices, 3) = -states(indices, 3);
indices = states(:,2) >= top_wall2*0.99 & states(:,1) > left_wall & states(:,1) < right_wall;
states(indices, 4) = -states(indices, 4);
end