1 function [B, id] = nrbbasisfun (points, nrb)
3 % NRBBASISFUN: Basis functions for NURBS
7 % B = nrbbasisfun (u, crv)
8 % B = nrbbasisfun ({u, v}, srf)
9 % [B, N] = nrbbasisfun ({u, v}, srf)
10 % [B, N] = nrbbasisfun (p, srf)
14 % u or p(1,:,:) - parametric points along u direction
15 % v or p(2,:,:) - parametric points along v direction
21 % B - Value of the basis functions at the points
22 % size(B)=[numel(u),(p+1)] for curves
23 % or [numel(u)*numel(v), (p+1)*(q+1)] for surfaces
25 % N - Indices of the basis functions that are nonvanishing at each
26 % point. size(N) == size(B)
29 % Copyright (C) 2009 Carlo de Falco
31 % This program is free software: you can redistribute it and/or modify
32 % it under the terms of the GNU General Public License as published by
33 % the Free Software Foundation, either version 2 of the License, or
34 % (at your option) any later version.
36 % This program is distributed in the hope that it will be useful,
37 % but WITHOUT ANY WARRANTY; without even the implied warranty of
38 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39 % GNU General Public License for more details.
41 % You should have received a copy of the GNU General Public License
42 % along with this program. If not, see <http://www.gnu.org/licenses/>.
46 || (~isstruct(nrb)) ...
47 || (iscell(points) && ~iscell(nrb.knots)) ...
48 || (~iscell(points) && iscell(nrb.knots) && (size(points,1)~=2)) ...
49 || (~iscell(nrb.knots) && (nargout>1)) ...
51 error('Incorrect input arguments in nrbbasisfun');
54 if (~iscell(nrb.knots)) %% NURBS curve
56 [B, id] = nrb_crv_basisfun__ (points, nrb);
58 elseif size(nrb.knots,2) == 2 %% NURBS surface
60 [v, u] = meshgrid(points{2}, points{1});
66 [B, id] = nrb_srf_basisfun__ (p, nrb);
69 error('The function nrbbasisfun is not yet ready for volumes')
74 %! U = [0 0 0 0 1 1 1 1];
75 %! x = [0 1/3 2/3 1] ;
78 %! nrb = nrbmak ([x;y;y;w], U);
79 %! u = linspace(0, 1, 30);
80 %! B = nrbbasisfun (u, nrb);
81 %! xplot = sum(bsxfun(@(x,y) x.*y, B, x),2);
83 %! title('Cubic Bernstein polynomials')
87 %! U = [0 0 0 0 1 1 1 1];
88 %! x = [0 1/3 2/3 1] ;
91 %! nrb = nrbmak ([x;y;y;w], U);
92 %! u = linspace(0, 1, 30);
93 %! B = nrbbasisfun (u, nrb);
94 %! xplot = sum(bsxfun(@(x,y) x.*y, B, x),2);
97 %! nrb2 = nrbmak ([x.*w;yy;y;w], U);
98 %! aux = nrbeval(nrb2,u);
99 %! %figure, plot(xplot, B(:,1), aux(1,:).', w(1)*aux(2,:).')
100 %! assert(B(:,1), w(1)*aux(2,:).', 1e-6)
102 %! yy = y; yy(2) = 1;
103 %! nrb2 = nrbmak ([x.*w;yy;y;w], U);
104 %! aux = nrbeval(nrb2, u);
105 %! %figure, plot(xplot, B(:,2), aux(1,:).', w(2)*aux(2,:).')
106 %! assert(B(:,2), w(2)*aux(2,:).', 1e-6)
108 %! yy = y; yy(3) = 1;
109 %! nrb2 = nrbmak ([x.*w;yy;y;w], U);
110 %! aux = nrbeval(nrb2,u);
111 %! %figure, plot(xplot, B(:,3), aux(1,:).', w(3)*aux(2,:).')
112 %! assert(B(:,3), w(3)*aux(2,:).', 1e-6)
114 %! yy = y; yy(4) = 1;
115 %! nrb2 = nrbmak ([x.*w;yy;y;w], U);
116 %! aux = nrbeval(nrb2,u);
117 %! %figure, plot(xplot, B(:,4), aux(1,:).', w(4)*aux(2,:).')
118 %! assert(B(:,4), w(4)*aux(2,:).', 1e-6)
121 %! p = 2; q = 3; m = 4; n = 5;
123 %! nrb = nrb4surf ([0 0], [1 0], [0 1], [1 1]);
124 %! nrb = nrbdegelev (nrb, [p-1, q-1]);
125 %! aux1 = linspace(0,1,m); aux2 = linspace(0,1,n);
126 %! nrb = nrbkntins (nrb, {aux1(2:end-1), aux2(2:end-1)});
127 %! u = rand (1, 30); v = rand (1, 10);
128 %! u = u - min (u); u = u / max (u);
129 %! v = v - min (v); v = v / max (v);
130 %! [B, N] = nrbbasisfun ({u, v}, nrb);
131 %! assert (sum(B, 2), ones(300, 1), 1e-6)
132 %! assert (all (all (B<=1)), true)
133 %! assert (all (all (B>=0)), true)
134 %! assert (all (all (N>0)), true)
135 %! assert (all (all (N <= prod (nrb.number))), true)
136 %! assert (max (max (N)),prod (nrb.number))
137 %! assert (min (min (N)),1)