-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnormalFilter.m
More file actions
25 lines (24 loc) · 818 Bytes
/
normalFilter.m
File metadata and controls
25 lines (24 loc) · 818 Bytes
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
function Ns = normalFilter(Ns,NBs,plane)
n = zeros(size(Ns,1),2);
for i = 1:size(Ns,1)
NB = [Ns(NBs{i,1},:) zeros(size(NBs{i,1},1),1); Ns(i,:) 0];
ids = nchoosek(1:size(NB,1),2);
angs = atan2d(dot(cross(...
NB(ids(:,1),:),NB(ids(:,2),:)),...
repmat(cross(plane(4:6),plane(7:9)),size(ids,1),1),2),...
dot(NB(ids(:,1),:),NB(ids(:,2),:),2));
[~,I] = min(abs(angs));
ni = NB(ids(I,1),:) + NB(ids(I,2),:);
NB([ids(I,:)],:) = [];
while ~isempty(NB)
angs = atan2d(dot(cross(repmat(ni,size(NB,1),1),NB),...
repmat(cross(plane(4:6),plane(7:9)),size(NB,1),1),2),...
dot(repmat(ni,size(NB,1),1),NB,2));
[~,I] = min(abs(angs));
ni = ni + NB(I,:);
NB(I,:) = [];
end
n(i,:) = ni(1:2)./norm(ni(1:2));
end
Ns = n;
end