1 function B = basisfun (iv, uv, p, U)
3 % BASISFUN: Basis function for B-Spline
7 % N = basisfun(iv,uv,p,U)
11 % iv - knot span ( from FindSpan() )
12 % uv - parametric points
18 % N - Basis functions vector(numel(uv)*(p+1))
20 % Adapted from Algorithm A2.2 from 'The NURBS BOOK' pg70.
22 % Copyright (C) 2000 Mark Spink
23 % Copyright (C) 2007 Daniel Claxton
24 % Copyright (C) 2009 Carlo de Falco
26 % This program is free software: you can redistribute it and/or modify
27 % it under the terms of the GNU General Public License as published by
28 % the Free Software Foundation, either version 2 of the License, or
29 % (at your option) any later version.
31 % This program is distributed in the hope that it will be useful,
32 % but WITHOUT ANY WARRANTY; without even the implied warranty of
33 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 % GNU General Public License for more details.
36 % You should have received a copy of the GNU General Public License
37 % along with this program. If not, see <http://www.gnu.org/licenses/>.
39 B = zeros(numel(uv), p+1);
43 i = iv(jj) + 1; %% findspan uses 0-based numbering
51 left(j+1) = u - U(i+1-j);
52 right(j+1) = U(i+j) - u;
56 temp = N(r+1)/(right(r+2) + left(j-r+1));
57 N(r+1) = saved + right(r+2)*temp;
58 saved = left(j-r+1)*temp;
72 %! U = [0 0 0 1/2 1 1 1];
74 %! u = linspace (0, 1, 10);
75 %! s = findspan (n, p, u, U);
76 %! Bref = [1.00000 0.00000 0.00000
77 %! 0.60494 0.37037 0.02469
78 %! 0.30864 0.59259 0.09877
79 %! 0.11111 0.66667 0.22222
80 %! 0.01235 0.59259 0.39506
81 %! 0.39506 0.59259 0.01235
82 %! 0.22222 0.66667 0.11111
83 %! 0.09877 0.59259 0.30864
84 %! 0.02469 0.37037 0.60494
85 %! 0.00000 0.00000 1.00000];
86 %! B = basisfun (s, u, p, U);
87 %! assert (B, Bref, 1e-5);