-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoints2cubes.m
152 lines (130 loc) · 4.97 KB
/
points2cubes.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
function [resultMat,mapping] = points2cubes( myMat,distX,distY,distTime )
% Algorithm 1 preprocessing in paper
% input: myMat, points sequence of a trajectory.
% distX, Epsilon_x in paper, longitude distance.
% distY, Epsilon_y in paper, latitude distance.
% distTime, Tau in paper, time distance.
LongColNum = 3;
LatColNum = 4;
[n,~] = size(myMat);
myMat2 = zeros(n,10);
indexTop = 1;
mapping = zeros(n,4);
mapping(:,3) = (1:n)';
mapping(1,4) = 1;
myStart = 1;
minX = myMat(1,LongColNum);
maxX = myMat(1,LongColNum);
minY = myMat(1,LatColNum);
maxY = myMat(1,LatColNum);
minTime = myMat(1,2);
maxTime = myMat(1,2);
newMinX = minX;
newMaxX = maxX;
newMinY = minY;
newMaxY = maxY;
newMinTime = minTime;
newMaxTime = maxTime;
for i = 2:n
flag = 1;
if (myMat(i,2) - myMat(myStart,2)) > distTime
flag = 0;
end
if flag
if myMat(i,LongColNum) > maxX
if myMat(i,LongColNum) - minX < distX
newMaxX = myMat(i,LongColNum);
else
flag = 0;
end
elseif myMat(i,LongColNum) < minX
if maxX - myMat(i,LongColNum) < distX
newMinX = myMat(i,LongColNum);
else
flag = 0;
end
end
end
if flag
if myMat(i,LatColNum) > maxY
if myMat(i,LatColNum) - minY < distY
newMaxY = myMat(i,LatColNum);
else
flag = 0;
end
elseif myMat(i,LatColNum) < minY
if maxY - myMat(i,LatColNum) < distY
newMinY = myMat(i,LatColNum);
else
flag = 0;
end
end
end
if flag
minX = newMinX;
maxX = newMaxX;
minY = newMinY;
maxY = newMaxY;
mapping(i,4) = indexTop;
else
myEnd = i - 1;
if myEnd == myStart
if myStart == 1
myEnd = 2;
elseif myStart < n
myEnd = i;
end
end
myMat2(indexTop,9) = myMat(myStart,2);
myMat2(indexTop,10) = myMat(myEnd,2);
myMat2(indexTop,11) = myMat(myStart,3);
myMat2(indexTop,12) = myMat(myEnd,3);
myMat2(indexTop,13) = myMat(myStart,4);
myMat2(indexTop,14) = myMat(myEnd,4);
myMat2(indexTop,2) = (myMat2(indexTop,9) + myMat2(indexTop,10)) / 2;
myMat2(indexTop,3) = (minX + maxX) / 2;
myMat2(indexTop,4) = (minY + maxY) / 2;
myMat2(indexTop,6) = getDistance( myMat(myStart,LatColNum), myMat(myEnd,LongColNum) ,myMat(myStart,LatColNum) ,myMat(myStart,LongColNum) );
if ( myMat(myEnd,LongColNum) - myMat(myStart,LongColNum) ) < 0
myMat2(indexTop,6) = - myMat2(indexTop,6);
end
myMat2(indexTop,7) = getDistance( myMat(myEnd,LatColNum) , myMat(myStart,LongColNum),myMat(myStart,LatColNum) ,myMat(myStart,LongColNum));
if (myMat(myEnd,LatColNum) - myMat(myStart,LatColNum)) < 0
myMat2(indexTop,7) = - myMat2(indexTop,7);
end
myMat2(indexTop,8) = round( atan2d( myMat2(indexTop,7) , myMat2(indexTop,6) ) );
minX = myMat(i,LongColNum);
maxX = myMat(i,LongColNum);
minY = myMat(i,LatColNum);
maxY = myMat(i,LatColNum);
minTime = myMat(i,2);
maxTime = myMat(i,2);
newMinX = minX;
newMaxX = maxX;
newMinY = minY;
newMaxY = maxY;
indexTop = indexTop + 1;
mapping(i,4) = indexTop;
myStart = i;
end
end
if n == myStart && myStart > 1
myEnd = n;
myStart = n-1;
else
myEnd = n;
end
myMat2(indexTop,6) = myMat(myEnd,LongColNum) - myMat(myStart,LongColNum);
myMat2(indexTop,7) = myMat(myEnd,LatColNum) - myMat(myStart,LatColNum);
myMat2(indexTop,8) = round( atan2d( myMat2(indexTop,7) , myMat2(indexTop,6) ) );
myMat2(indexTop,9) = myMat(myStart,2);
myMat2(indexTop,10) = myMat(myEnd,2);
myMat2(indexTop,11) = myMat(myStart,3);
myMat2(indexTop,12) = myMat(myEnd,3);
myMat2(indexTop,13) = myMat(myStart,4);
myMat2(indexTop,14) = myMat(myEnd,4);
myMat2(indexTop,2) = (myMat2(indexTop,9) + myMat2(indexTop,10)) / 2;
myMat2(indexTop,3) = (minX + maxX) / 2;
myMat2(indexTop,4) = (minY + maxY) / 2;
resultMat = myMat2( 1:indexTop ,: );
end