-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtoBPFZ_test.m
143 lines (121 loc) · 3.24 KB
/
toBPFZ_test.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
function toBPFZ_test(Kminus1)
arguments
Kminus1(1,1) double = 1
end
K = Kminus1 + 1;
npts = 500;
qlist = get_cubo(npts);
nAlist = zeros(npts,3);
rng(12)
nAlist(1,:)= normr(rand(3,1).');
nAlist(2:npts,:) = normr(rand(3,npts-1).'-0.5);
posIDs = find(all(nAlist(2:npts,:) > 0,2)); %positive IDs
exID = posIDs(2);
nAex = nAlist(exID,:); %example
addpathdir('q2rod.m')
pgnum = 32;
%get symmetrically equivalent ones
[nAout,nArot,nR] = toBPFZ(qlist,nAlist,'pgnum',pgnum);
%example
% nAoutex = nAout(posID1,:);
nArotex = nArot{exID+1};
%reference normal
refnum = 32;
if refnum > 2*nR
refnum = randi(2*nR);
end
nAref = nArot{1}(refnum,:);
% nAref = nArot{1}(2,:);
%% plotting
paperfigure(1,2);
tnum = 1;
nexttile(tnum) % voronoi cell point cloud
nAsub = nArot(2:end);
v = num2cell(randi(nR,npts-1,1));
nAdata = cellfun(@(x,i) x(i,:),nAsub,v,'UniformOutput',false);
nAdata = vertcat(nAdata{:});
nAdata = [nAdata;-nAdata];
t = n2c(nAdata);
plot3(t{:},'r.')
ax = gca;
ax.View = [140 35];
hold on
[k,D] = cellfun(@(x) knnsearch(x,nAref,'K',K,'IncludeTies',true),nAsub);
klen = cellfun(@length,k);
D1 = cellfun(@(x) x(1),D);
D2 = cellfun(@(x) x(2),D);
[pts,t] = cellvertcat(nAsub,k,1);
% kex = k{posID1}(1); %example
% nAsubex = nAsub{posID1};
ptex = pts(exID,:);
if any(D1 == D2)
warning('more than one minimum found for at least one point')
end
% nnID = 1;
% pts = cellfun(@(x,i) x(i(nnID),:),nAsub,k,'UniformOutput',false);
% pts = vertcat(pts{:});
% clist = {'b','g','y','c','m','w'};
clist = {'b','','','','','',''};
for i = 1:K-1
cellvertcatplot(nAsub,k,i,clist{i});
end
%reference unit normal
t = n2c(nAref*1.02);
plot3(t{:},'ko','MarkerFaceColor','w')
% quivplot(1.5)
axis equal tight off
test_voronoisphere(nArot{1}.');
if K == 2
lgdlbltmp = {'$p_i^*$ (symmetrized)'};
lgdlbl = ['$p_{i,1}$ (starting)',lgdlbltmp,'$p_\mathrm{ref}$ (reference)'];
legend(lgdlbl,'Location','north','Interpreter','latex')
% legend('starting',lgdlbltmp{:},'reference','Location','north')
else
lgdlbltmp = strcat('NN',{' '},num2cell(num2str((1:K-1).')));
legend('starting',lgdlbltmp{:},'reference','Location','southeast')
end
papertext(tnum);
tnum = 2;
nexttile(tnum) %voronoi cell, single intersection example
hold on
t = n2c(setdiff(nArotex,ptex,'rows'));
plot3(t{:},'m.')
t = n2c(ptex);
plot3(t{:},'b.')
t = n2c(nAref*1.02);
plot3(t{:},'ko','MarkerFaceColor','w')
papertext(tnum);
ax = gca;
ax.View = [140 35];
test_voronoisphere(nArot{1}.')
axis equal tight off
% lgdlbl = {'p_i','p_i^*','p_\rmmath{ref}'};
% lgdlbl = {'starting','symmetrized','reference'};
lgdlbltmp = {'$p_1^*$ (symmetrized)'};
lgdlbl = ['$p_{1,j}$ (starting)',lgdlbltmp,'$p_\mathrm{ref}$ (reference)'];
legend(lgdlbl,'Location','north','Interpreter','latex')
end
function cellvertcatplot(x,k,nnID,c)
[~,t] = cellvertcat(x,k,nnID);
plot3(t{:},[c '.'])
end
function [pts,t] = cellvertcat(x,k,nnID)
pts = cellfun(@(x,i) x(i(nnID),:),x,k,'UniformOutput',false);
pts = vertcat(pts{:});
t = n2c(pts);
end
%% CODE GRAVEYARD
%{
% t=n2c(pts);
% plot3(t{:},'.')
%
% nnID = 2;
% pts2 = cellfun(@(x,i) x(i(nnID),:),nAsub,k,'UniformOutput',false);
% pts2 = vertcat(pts2{:});
%
% t=n2c(pts2);
% plot3(t{:},'.')
% if ~all(klen == K)
% warning('more than one minimum found for at least one point')
% end
%}