1 function dersv = basisfunder (ii, pl, uu, u_knotl, nders)
3 % BASISFUNDER: B-Spline Basis function derivatives.
7 % ders = basisfunder (ii, pl, uu, k, nd)
11 % ii - knot span index (see findspan)
12 % pl - degree of curve
13 % uu - parametric points
15 % nd - number of derivatives to compute
19 % ders - ders(n, i, :) (i-1)-th derivative at n-th point
21 % Adapted from Algorithm A2.3 from 'The NURBS BOOK' pg72.
23 % Copyright (C) 2009,2011 Rafael Vazquez
25 % This program is free software: you can redistribute it and/or modify
26 % it under the terms of the GNU General Public License as published by
27 % the Free Software Foundation, either version 2 of the License, or
28 % (at your option) any later version.
30 % This program is distributed in the hope that it will be useful,
31 % but WITHOUT ANY WARRANTY; without even the implied warranty of
32 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 % GNU General Public License for more details.
35 % You should have received a copy of the GNU General Public License
36 % along with this program. If not, see <http://www.gnu.org/licenses/>.
38 dersv = zeros(numel(uu), nders+1, pl+1);
42 i = ii(jj)+1; %% convert to base-1 numbering of knot spans
45 ders = zeros(nders+1,pl+1);
46 ndu = zeros(pl+1,pl+1);
52 left(j+1) = u - u_knotl(i+1-j);
53 right(j+1) = u_knotl(i+j) - u;
56 ndu(j+1,r+1) = right(r+2) + left(j-r+1);
57 temp = ndu(r+1,j)/ndu(j+1,r+1);
58 ndu(r+1,j+1) = saved + right(r+2)*temp;
59 saved = left(j-r+1)*temp;
64 ders(1,j+1) = ndu(j+1,pl+1);
70 for k = 1:nders %compute kth derivative
75 a(s2+1,1) = a(s1+1,1)/ndu(pk+2,rk+1);
76 d = a(s2+1,1)*ndu(rk+1,pk+1);
89 a(s2+1,j+1) = (a(s1+1,j+1) - a(s1+1,j))/ndu(pk+2,rk+j+1);
90 d = d + a(s2+1,j+1)*ndu(rk+j+1,pk+1);
93 a(s2+1,k+1) = -a(s1+1,k)/ndu(pk+2,r+1);
94 d = d + a(s2+1,k+1)*ndu(r+1,pk+1);
105 ders(k+1,j+1) = ders(k+1,j+1)*r;
110 dersv(jj, :, :) = ders;
117 %! k = [0 0 0 0 1 1 1 1];
120 %! i = findspan (numel(k)-p-2, p, u, k);
121 %! ders = basisfunder (i, p, u, k, 1);
122 %! sumders = sum (squeeze(ders), 2);
123 %! assert (sumders(1), 1, 1e-15);
124 %! assert (sumders(2:end), 0, 1e-15);
127 %! k = [0 0 0 0 1/3 2/3 1 1 1 1];
130 %! i = findspan (numel(k)-p-2, p, u, k);
131 %! ders = basisfunder (i, p, u, k, 7);
132 %! sumders = sum (squeeze(ders), 2);
133 %! assert (sumders(1), 1, 1e-15);
134 %! assert (sumders(2:end), zeros(rows(squeeze(ders))-1, 1), 1e-13);
137 %! k = [0 0 0 0 1/3 2/3 1 1 1 1];
139 %! u = rand (100, 1);
140 %! i = findspan (numel(k)-p-2, p, u, k);
141 %! ders = basisfunder (i, p, u, k, 7);
143 %! sumders = sum (squeeze(ders(ii,:,:)), 2);
144 %! assert (sumders(1), 1, 1e-15);
145 %! assert (sumders(2:end), zeros(rows(squeeze(ders(ii,:,:)))-1, 1), 1e-13);
147 %! assert (ders(:, (p+2):end, :), zeros(numel(u), 8-p-1, p+1), 1e-13)
148 %! assert (all(all(ders(:, 1, :) <= 1)), true)