-
Notifications
You must be signed in to change notification settings - Fork 2
/
distance_to_obstacles.m
50 lines (44 loc) · 1.19 KB
/
distance_to_obstacles.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
function distance = distance_to_obstacles(current_position_x, current_position_y)
global map;
global map_size;
distance_east = 0;
if (current_position_x < map_size)
for i = current_position_x + 1:1:map_size
if map(current_position_y, i) == 0
break;
else
distance_east = distance_east + 1;
end
end
end
distance_west = 0;
if (current_position_x > 1)
for i = current_position_x - 1:-1:1
if map(current_position_y, i) == 0
break;
else
distance_west = distance_west + 1;
end
end
end
distance_north = 0;
if (current_position_y > 1)
for i = current_position_y - 1:-1:1
if map(i,current_position_x) == 0
break;
else
distance_north = distance_north + 1;
end
end
end
distance_south = 0;
if (current_position_y < map_size)
for i = current_position_y + 1:1:map_size
if map(i,current_position_x) == 0
break;
else
distance_south = distance_south + 1;
end
end
end
distance = [distance_east, distance_north, distance_west, distance_south];