-
Notifications
You must be signed in to change notification settings - Fork 1
/
connectLine.m
41 lines (37 loc) · 870 Bytes
/
connectLine.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
function map = connectLine(p1,p2,map)
if p1(1)>p2(1)
tmp=p1;
p1=p2;
p2=tmp;
end
x_dif = p2(1)-p1(1); y_dif = p2(2)-p1(2);
add_ = y_dif/x_dif;
% Check if its too steep or too flat, the map drawing could be bad.
if abs(y_dif) < 4
if p2(1)<p1(1)
map(p2(2),p2(1):p1(1))=1;
else
map(p2(2),p1(1):p2(1))=1;
end
disp(['Catch ', 'x_dif = ', int2str(x_dif), ' y_dif = ', int2str(y_dif)])
return;
end
if abs(x_dif) < 4
if p2(2)<p1(2)
map(p2(2):p1(2),p2(1))=1;
else
map(p1(2):p2(2),p2(1))=1;
end
disp(['Catch ', 'x_dif = ', int2str(x_dif), ' y_dif = ', int2str(y_dif)])
return;
end
for i = 1: x_dif-1
y = add_*i+p1(2);
map(floor(y), p1(1)+i)=1;
map(ceil(y), p1(1)+i)=1;
if floor(y) == ceil(y)
map(floor(y)-1, p1(1)+i)=1;
map(ceil(y)+1, p1(1)+i)=1;
end
end
end