- don't allow n1 < 0

This commit is contained in:
2023-06-14 18:55:43 +02:00
parent 89e2cafd44
commit d8cdbc83c3
+20 -11
View File
@@ -22,29 +22,31 @@
## Author: Jens <jens@orion> ## Author: Jens <jens@orion>
## Created: 2023-06-10 ## Created: 2023-06-10
function [P1, Pa1, D] = vecfit (Pp, mask, Pt, P0, Pa0, step) function [P1, na_1, D] = vecfit (Pp, ignore_mask, Pt, P0, na_0, step)
[N_subst, N_elem] = size(Pp); [N_subst, N_elem] = size(Pp);
# Create default mask # Create default ignore_mask
if isempty(mask), if isempty(ignore_mask),
mask = ones(1,N_elem); ignore_mask = ones(1,N_elem);
end end
# A-Priory state with mask # A-Priory state with mask
P1 = P0 + sum(Pp.*Pa0.*mask); P1 = P0 + sum(Pp.*na_0.*ignore_mask);
# Calc distance to target # Calc distance to target
d = (Pt-P1); d = (Pt-P1);
D = norm(d); D = norm(d);
dn = d/D; dn = d/D;
subst_list = 1:N_subst;
while 1,
# Find best prototype # Find best prototype
best_i = 0; best_i = 0;
best_k = 10000; best_k = 10000;
best_dir = 1; best_dir = 1;
for i=subst_list,
for i=1:N_subst,
p = Pp(i,:); p = Pp(i,:);
pn = p/norm(p); pn = p/norm(p);
@@ -60,21 +62,28 @@ function [P1, Pa1, D] = vecfit (Pp, mask, Pt, P0, Pa0, step)
end end
# Calc next Pa # Calc next Pa
Pa1 = Pa0; na_1 = na_0;
# Calc P1 # Calc P1
P1 = P0 + sum(Pp.*Pa0); P1 = P0 + sum(Pp.*na_0);
if best_i, if best_i,
# Get value from best prototype # Get value from best prototype
delta = best_dir*step; delta = best_dir*step;
dps = delta*Pp(best_i,:); dps = delta*Pp(best_i,:);
# Check for negative n
accu = na_1(best_i) + delta;
if accu < 0,
subst_list(best_i) = [];
continue;
end
# Update point # Update point
P1 += dps; P1 += dps;
# Update Point accu # Update Point accu
Pa1(best_i) += delta; na_1(best_i) = accu;
break;
end
end end
endfunction endfunction