/usr/share/octave/packages/nurbs-1.3.13/basisfun.m is in octave-nurbs 1.3.13-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | function B = basisfun (iv, uv, p, U)
% BASISFUN: Basis function for B-Spline
%
% Calling Sequence:
%
% N = basisfun(iv,uv,p,U)
%
% INPUT:
%
% iv - knot span ( from FindSpan() )
% uv - parametric points
% p - spline degree
% U - knot sequence
%
% OUTPUT:
%
% N - Basis functions vector(numel(uv)*(p+1))
%
% Adapted from Algorithm A2.2 from 'The NURBS BOOK' pg70.
%
% See also:
%
% numbasisfun, basisfunder, findspan
%
% Copyright (C) 2000 Mark Spink
% Copyright (C) 2007 Daniel Claxton
% Copyright (C) 2009 Carlo de Falco
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program. If not, see <http://www.gnu.org/licenses/>.
B = zeros(numel(uv), p+1);
for jj = 1:numel(uv)
i = iv(jj) + 1; %% findspan uses 0-based numbering
u = uv(jj);
left = zeros(p+1,1);
right = zeros(p+1,1);
N(1) = 1;
for j=1:p
left(j+1) = u - U(i+1-j);
right(j+1) = U(i+j) - u;
saved = 0;
for r=0:j-1
temp = N(r+1)/(right(r+2) + left(j-r+1));
N(r+1) = saved + right(r+2)*temp;
saved = left(j-r+1)*temp;
end
N(j+1) = saved;
end
B (jj, :) = N;
end
end
%!test
%! n = 3;
%! U = [0 0 0 1/2 1 1 1];
%! p = 2;
%! u = linspace (0, 1, 10);
%! s = findspan (n, p, u, U);
%! Bref = [1.00000 0.00000 0.00000
%! 0.60494 0.37037 0.02469
%! 0.30864 0.59259 0.09877
%! 0.11111 0.66667 0.22222
%! 0.01235 0.59259 0.39506
%! 0.39506 0.59259 0.01235
%! 0.22222 0.66667 0.11111
%! 0.09877 0.59259 0.30864
%! 0.02469 0.37037 0.60494
%! 0.00000 0.00000 1.00000];
%! B = basisfun (s, u, p, U);
%! assert (B, Bref, 1e-5);
|