1 function varargout = nrbbasisfunder (points, nrb)
3 % NRBBASISFUNDER: NURBS basis functions derivatives
7 % Bu = nrbbasisfunder (u, crv)
8 % [Bu, N] = nrbbasisfunder (u, crv)
9 % [Bu, Bv] = nrbbasisfunder ({u, v}, srf)
10 % [Bu, Bv, N] = nrbbasisfunder ({u, v}, srf)
11 % [Bu, Bv, N] = nrbbasisfunder (p, srf)
15 % u or p(1,:,:) - parametric points along u direction
16 % v or p(2,:,:) - parametric points along v direction
22 % Bu - Basis functions derivatives WRT direction u
23 % size(Bu)=[numel(u),(p+1)] for curves
24 % or [numel(u)*numel(v), (p+1)*(q+1)] for surfaces
26 % Bv - Basis functions derivatives WRT direction v
27 % size(Bv)=[numel(v),(p+1)] for curves
28 % or [numel(u)*numel(v), (p+1)*(q+1)] for surfaces
30 % N - Indices of the basis functions that are nonvanishing at each
31 % point. size(N) == size(B)
33 % Copyright (C) 2009 Carlo de Falco
35 % This program is free software: you can redistribute it and/or modify
36 % it under the terms of the GNU General Public License as published by
37 % the Free Software Foundation, either version 2 of the License, or
38 % (at your option) any later version.
40 % This program is distributed in the hope that it will be useful,
41 % but WITHOUT ANY WARRANTY; without even the implied warranty of
42 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43 % GNU General Public License for more details.
45 % You should have received a copy of the GNU General Public License
46 % along with this program. If not, see <http://www.gnu.org/licenses/>.
51 || (~isstruct(nrb)) ...
52 || (iscell(points) && ~iscell(nrb.knots)) ...
53 || (~iscell(points) && iscell(nrb.knots) && (size(points,1)~=2)) ...
54 || (~iscell(nrb.knots) && (nargout>2)) ...
56 error('Incorrect input arguments in nrbbasisfun');
59 if (~iscell(nrb.knots)) %% NURBS curve
61 [varargout{1}, varargout{2}] = nrb_crv_basisfun_der__ (points, nrb);
63 elseif size(nrb.knots,2) == 2 %% NURBS surface
66 [v, u] = meshgrid(points{2}, points{1});
72 [varargout{1}, varargout{2}, varargout{3}] = nrb_srf_basisfun_der__ (p, nrb);
75 error('The function nrbbasisfunder is not yet ready for volumes')
80 %! U = [0 0 0 0 1 1 1 1];
81 %! x = [0 1/3 2/3 1] ;
84 %! nrb = nrbmak ([x;y;y;w], U);
85 %! u = linspace(0, 1, 30);
86 %! [Bu, id] = nrbbasisfunder (u, nrb);
88 %! title('Derivatives of the cubic Bernstein polynomials')
92 %! U = [0 0 0 0 1 1 1 1];
93 %! x = [0 1/3 2/3 1] ;
96 %! nrb = nrbmak ([x;y;y;w], U);
97 %! u = linspace(0, 1, 30);
98 %! [Bu, id] = nrbbasisfunder (u, nrb);
100 %! assert (sum(Bu, 2), zeros(numel(u), 1), 1e-10),
103 %! U = [0 0 0 0 1/2 1 1 1 1];
104 %! x = [0 1/4 1/2 3/4 1] ;
107 %! nrb = nrbmak ([x;y;y;w], U);
108 %! u = linspace(0, 1, 300);
109 %! [Bu, id] = nrbbasisfunder (u, nrb);
110 %! assert (sum(Bu, 2), zeros(numel(u), 1), 1e-10)
113 %! p = 2; q = 3; m = 4; n = 5;
115 %! nrb = nrb4surf ([0 0], [1 0], [0 1], [1 1]);
116 %! nrb = nrbdegelev (nrb, [p-1, q-1]);
117 %! aux1 = linspace(0,1,m); aux2 = linspace(0,1,n);
118 %! nrb = nrbkntins (nrb, {aux1(2:end-1), aux2(2:end-1)});
119 %! nrb.coefs (4,:,:) = nrb.coefs(4,:,:) + rand (size (nrb.coefs (4,:,:)));
120 %! [Bu, Bv, N] = nrbbasisfunder ({rand(1, 20), rand(1, 20)}, nrb);
121 %! #plot3(squeeze(u(1,:,:)), squeeze(u(2,:,:)), reshape(Bu(:,10), 20, 20),'o')
122 %! assert (sum (Bu, 2), zeros(20^2, 1), 1e-10)