1 function [N, Nder] = tbasisfun (u, p, U)
3 % TBASISFUN: Compute a B- or T-Spline basis function, and its derivatives, from its local knot vector.
7 % [N, Nder] = tbasisfun (u, p, U)
8 % [N, Nder] = tbasisfun ([u; v], [p q], {U, V})
9 % [N, Nder] = tbasisfun ([u; v; w], [p q r], {U, V, W})
13 % u or [u; v] : points in parameter space where the basis function is to be
16 % U or {U, V} : local knot vector
18 % p or [p q] : polynomial order of the basis function
22 % N : basis function evaluated at the given parametric points
23 % Nder : basis function gradient evaluated at the given parametric points
25 % Copyright (C) 2009 Carlo de Falco
26 % Copyright (C) 2012 Rafael Vazquez
28 % This program is free software: you can redistribute it and/or modify
29 % it under the terms of the GNU General Public License as published by
30 % the Free Software Foundation, either version 2 of the License, or
31 % (at your option) any later version.
33 % This program is distributed in the hope that it will be useful,
34 % but WITHOUT ANY WARRANTY; without even the implied warranty of
35 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36 % GNU General Public License for more details.
38 % You should have received a copy of the GNU General Public License
39 % along with this program. If not, see <http://www.gnu.org/licenses/>.
44 error ('tbasisfun: knot vector and degree do not correspond')
48 N = onebasisfun__ (u, p, U);
50 [N, Nder] = onebasisfunder__ (u, p, U);
53 elseif (size(U,2) == 2)
54 U{1} = sort(U{1}); U{2} = sort(U{2});
55 if (numel(U{1}) ~= p(1)+2 || numel(U{2}) ~= p(2)+2)
56 error ('tbasisfun: knot vector and degree do not correspond')
60 Nu = onebasisfun__ (u(1,:), p(1), U{1});
61 Nv = onebasisfun__ (u(2,:), p(2), U{2});
65 [Nu, Ndu] = onebasisfunder__ (u(1,:), p(1), U{1});
66 [Nv, Ndv] = onebasisfunder__ (u(2,:), p(2), U{2});
73 elseif (size(U,2) == 3)
74 U{1} = sort(U{1}); U{2} = sort(U{2}); U{3} = sort(U{3});
75 if (numel(U{1}) ~= p(1)+2 || numel(U{2}) ~= p(2)+2 || numel(U{3}) ~= p(3)+2)
76 error ('tbasisfun: knot vector and degree do not correspond')
80 Nu = onebasisfun__ (u(1,:), p(1), U{1});
81 Nv = onebasisfun__ (u(2,:), p(2), U{2});
82 Nw = onebasisfun__ (u(3,:), p(3), U{3});
86 [Nu, Ndu] = onebasisfunder__ (u(1,:), p(1), U{1});
87 [Nv, Ndv] = onebasisfunder__ (u(2,:), p(2), U{2});
88 [Nw, Ndw] = onebasisfunder__ (u(3,:), p(3), U{3});
91 Nder(1,:) = Ndu.*Nv.*Nw;
92 Nder(2,:) = Nu.*Ndv.*Nw;
93 Nder(3,:) = Nu.*Nv.*Ndw;
100 %! U = {[0 0 1/2 1 1], [0 0 0 1 1]};
102 %! [X, Y] = meshgrid (linspace(0, 1, 30));
103 %! u = [X(:), Y(:)]';
104 %! N = tbasisfun (u, p, U);
105 %! surf (X, Y, reshape (N, size(X)))
106 %! title('Basis function associated to a local knot vector')
112 %! u = [0.3 0.4 0.6 0.7];
113 %! [N, Nder] = tbasisfun (u, p, U);
114 %! assert (N, [0.6 0.8 0.8 0.6], 1e-12);
115 %! assert (Nder, [2 2 -2 -2], 1e-12);
118 %! U = {[0 1/2 1] [0 1/2 1]};
120 %! u = [0.3 0.4 0.6 0.7; 0.3 0.4 0.6 0.7];
121 %! [N, Nder] = tbasisfun (u, p, U);
122 %! assert (N, [0.36 0.64 0.64 0.36], 1e-12);
123 %! assert (Nder, [1.2 1.6 -1.6 -1.2; 1.2 1.6 -1.6 -1.2], 1e-12);
126 %! U = {[0 1/2 1] [0 1/2 1] [0 1/2 1]};
128 %! u = [0.4 0.4 0.6 0.6; 0.4 0.4 0.6 0.6; 0.4 0.6 0.4 0.6];
129 %! [N, Nder] = tbasisfun (u, p, U);
130 %! assert (N, [0.512 0.512 0.512 0.512], 1e-12);
131 %! assert (Nder, [1.28 1.28 -1.28 -1.28; 1.28 1.28 -1.28 -1.28; 1.28 -1.28 1.28 -1.28], 1e-12);