-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathupdate_edge_divisions_parallel.m
49 lines (43 loc) · 1.32 KB
/
update_edge_divisions_parallel.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
function edges = update_edge_divisions_parallel(edge, P)
E0 = edge(1,:);
E1 = edge(end,:);
nPointsIn = size(edge,1);
nPointsOut = P+2;
edges = zeros(nPointsOut,2);
edges(1,:) = E0;
edges(end,:) = E1;
divided_edge_length = compute_divided_edge_length(edge);
segment_length = divided_edge_length / (P + 1);
eps = 1e-6;
for p = 2:1:nPointsOut-1
c = 2;
current_segment_length = segment_length;
done = false;
for i = 2:1:nPointsIn
old_segment_length = norm(edge(i,:) - edge(i-1,:));
while ((old_segment_length - current_segment_length) > eps)
percent_position = current_segment_length / old_segment_length;
if (c == p)
done = true;
break;
end
c = c + 1;
old_segment_length = old_segment_length - current_segment_length;
current_segment_length = segment_length;
end
if (done)
fprintf('ratio = %f\n', percent_position);
break;
end
current_segment_length = current_segment_length - old_segment_length;
end
edges(c, :) = edge(i-1,:) + percent_position*(edge(i,:) - edge(i-1,:));
end
end
function len = compute_divided_edge_length(edge)
nPoints = size(edge,1);
len = 0;
for j = 2:nPoints
len = len + norm(edge(j,:) - edge(j-1,:));
end
end