1 function s = findspan(n,p,u,U)
2 % FINDSPAN Find the span of a B-Spline knot vector at a parametric point
6 % s = findspan(n,p,u,U)
10 % n - number of control points - 1
12 % u - parametric point
19 % Modification of Algorithm A2.1 from 'The NURBS BOOK' pg68
21 % Copyright (C) 2010 Rafael Vazquez
23 % This program is free software: you can redistribute it and/or modify
24 % it under the terms of the GNU General Public License as published by
25 % the Free Software Foundation, either version 2 of the License, or
26 % (at your option) any later version.
28 % This program is distributed in the hope that it will be useful,
29 % but WITHOUT ANY WARRANTY; without even the implied warranty of
30 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 % GNU General Public License for more details.
33 % You should have received a copy of the GNU General Public License
34 % along with this program. If not, see <http://www.gnu.org/licenses/>.
36 if (max(u(:))>U(end) || min(u(:))<U(1))
37 error('Some value is outside the knot span')
42 if (u(j)==U(n+2)), s(j)=n; continue, end
43 s(j) = find(u(j) >= U,1,'last')-1;
50 %! U = [0 0 0 1/2 1 1 1];
52 %! u = linspace(0, 1, 10);
53 %! s = findspan (n, p, u, U);
54 %! assert (s, [2*ones(1, 5) 3*ones(1, 5)]);
57 %! p = 2; m = 7; n = m - p - 1;
58 %! U = [zeros(1,p) linspace(0,1,m+1-2*p) ones(1,p)];
59 %! u = [ 0 0.11880 0.55118 0.93141 0.40068 0.35492 0.44392 0.88360 0.35414 0.92186 0.83085 1];
60 %! s = [2 2 3 4 3 3 3 4 3 4 4 4];
61 %! assert (findspan (n, p, u, U), s, 1e-10);