-
Notifications
You must be signed in to change notification settings - Fork 2
/
findspan.m
44 lines (42 loc) · 2.03 KB
/
findspan.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
function s = findspan(n,p,u,U)
% FINDSPAN Find the span of a B-Spline knot vector at a parametric point
% -------------------------------------------------------------------------
% ADAPTATION of FINDSPAN from C
% -------------------------------------------------------------------------
%
% Calling Sequence:
%
% s = findspan(n,p,u,U)
%
% INPUT:
%
% n - number of control points - 1
% p - spline degree
% u - parametric point
% U - knot sequence
%
% RETURN:
%
% s - knot span
%
% Algorithm A2.1 from 'The NURBS BOOK' pg68
% int findspan(int n, int p, double u, double *U) {
% int low, high, mid;
% // special case
if (u==U(n+2)), s=n; return, end % if (u == U[n+1]) return(n);
%
% // do binary search
low = p; % low = p;
high = n + 1; % high = n + 1;
mid = floor((low + high) / 2); % mid = (low + high) / 2;
while (u < U(mid+1) || u >= U(mid+2)) % while (u < U[mid] || u >= U[mid+1]) {
if (u < U(mid+1)) % if (u < U[mid])
high = mid; % high = mid;
else % else
low = mid; % low = mid;
end
mid = floor((low + high) / 2); % mid = (low + high) / 2;
end % }
%
s = mid; % return(mid);
% }