-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcharacteristic_points.m
136 lines (117 loc) · 3.19 KB
/
characteristic_points.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
function [ partp ] = characteristic_points( track )
%CHARACTERISTIC_POINTS Computes the number of points necessary to describe
% the trajectory using MDL
n = size(track, 2);
start = 1;
len = 1;
partp = 1; %Start point only
%tolerance = 0;
while start + len <= n
current = start + len;
cost_par = mdl(track, start, current, 1);
cost_nopar = mdl(track, start, current, 0);
if cost_par > cost_nopar
%if tolerance == 2
% current = current - tolerance;
% tolerance = 0;
start = current - 1;
len = 1;
partp = partp + 1;
%else
% len = len + 1;
% tolerance = tolerance + 1;
%end
else
len = len + 1;
%tolerance = 0;
end
end
partp = partp + 1; %Add end point
end
function [ mdl_score ] = mdl( track, start, current, part )
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
if part
partition = [start, current];
else
partition = start:current;
end
L_H = 0;
L_DH = 0;
for j=1:length(partition)-1
pc1 = track(:, partition(j));
pc2 = track(:, partition(j+1));
L_H = L_H + ceil(log2(norm(pc2-pc1)));
for k=partition(j):partition(j+1)-1
p1 = track(:, k);
p2 = track(:, k+1);
dp = dperp(pc1, pc2, p1, p2);
dt = dtheta(pc1, pc2, p1, p2);
%fprintf('k: %d, prt(j): %d, prt(j+1): %d\n', k, partition(j), partition(j+1));
%To take logarithms
if dp < 1
dp = 1;
end
if dt < 1
dt = 1;
end
L_DH = L_DH + ceil(log2(dp)) + ceil(log2(dt));
%L_DH_perp = L_DH_perp + dp;
%L_DH_theta = L_DH_theta + dt;
end
%L_DH = log2(L_DH_perp) + log2(L_DH_theta);
end
mdl_score = L_H + L_DH;
end
function [ dp ] = dperp( pc1, pc2, p1, p2 )
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
if norm(pc2-pc1) >= norm(p2-p1)
s = pc1;
e = pc2;
p = [p1, p2];
else
s = p1;
e = p2;
p = [pc1, pc2];
end
l1 = distance2segment(s, e, p(:, 1));
l2 = distance2segment(s, e, p(:, 2));
if l1 == 0 && l2 == 0
dp = 0;
else
dp = (l1^2+l2^2)/(l1+l2);
end
end
function [ d ] = distance2segment( s, e, p )
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
if norm(e-s) == 0 || norm(p-s) == 0
d = 0;
return;
end
proj_p = ((p-s)'*(e-s)/(norm(e-s)^2))*(e-s);
d = norm(p-s-proj_p);
end
function [ dt ] = dtheta( pc1, pc2, p1, p2 )
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
Lc = norm(pc2-pc1);
Lp = norm(p2-p1);
vc = (pc2-pc1)/norm(pc2-pc1);
vp = (p2-p1)/norm(p2-p1);
ctheta = vc'*vp;
if ctheta > 1 %Numerical problems, which lead to a cos(theta) slightly higher than 1 (~1+1e-7)
ctheta = 1;
end
if ctheta < 0 %Angle > 90º, d_theta = min(Lc, Lp);
ctheta = 0;
end
dt = min(Lc, Lp)*sin(acos(ctheta));
% theta = atan2(norm(cross([pc2-pc1;0],[p2-p1;0])),dot(pc2-pc1,p2-p1))
% if -pi/2 < theta < pi/2
% dt = min(Lc, Lp)*sin(theta);
% else
% dt = min(Lc, Lp);
% end
end