This repository has been archived by the owner on Mar 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
/
FDSInit.m
77 lines (64 loc) · 1.94 KB
/
FDSInit.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
function out = FDSInit(startPos, endPos, map, scalling)
%% generate shape pattern
radius = 10/scalling;
mat = zeros(radius*2,radius*2);
dista = @(a,b) sqrt(a*a+b*b);
shapePattern = [];
for x = 1:1:2*radius
for y =1:1:2*radius
if dista(x-radius-0.5,y-radius-0.5) > radius -1 && dista(x-radius-0.5,y-radius-0.5) < radius
mat(x,y) = 1;
shapePattern = [shapePattern; floor(x-radius) floor(y-radius) 0 0];
end
end
end
neighbours = [
0 1 0 0;
-1 0 0 0;
0 -1 0 0;
1 1 0 0;
-1 -1 0 0;
1 0 0 0;
1 -1 0 0;
-1 1 0 0;
]';
%% prepare all data
out.map = map;
out.startPos = [startPos(2:-1:1); 0; 0];
out.endPos = [endPos(2:-1:1); 0; 0];
startPos = out.startPos;
out.sacalling = scalling;
out.pattern = shapePattern';
out.ucc = neighbours;
out.height = ceil(length(out.map(:,1)));
out.width = ceil(length(out.map(1,:)));
out.graph = zeros(out.height, out.width,7);
out.graph(:,:,1:2) = inf;
out.graph(:,:,3) = -1;
out.graph(:,:,5) = -1;
out.graph(:,:,6) = 0;
out.graph(:,:,7) = 0;
out.kM = 0;
SQRT2 = sqrt(2)-1;
out.comparator = DStarcmp;
out.stack = java.util.PriorityQueue(180247, out.comparator);
setk(out.endPos, 0);
seth(out.endPos, 0);
setQ(out.endPos);
out.endPos(3:4) = [heur(out.endPos); 0];
add(out.stack, out.endPos);
%-----------------------------------------------------------
function setQ(s)
out.graph(s(1), s(2), 3) = 1;
end
function seth(s, val)
out.graph(s(1), s(2),1) = val;
end
function setk(s, val)
out.graph(s(1), s(2),2) = val;
end
function out = heur(s)
k = abs(startPos - s);
out = SQRT2*min(k(1:2)) + max(k(1:2));
end
end