-
Notifications
You must be signed in to change notification settings - Fork 2
/
basisfun.m
49 lines (44 loc) · 2.32 KB
/
basisfun.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
45
46
47
48
49
function N = basisfun(i,u,p,U)
% BASISFUN Basis function for B-Spline
% -------------------------------------------------------------------------
% ADAPTATION of BASISFUN from C Routine
% -------------------------------------------------------------------------
%
% Calling Sequence:
%
% N = basisfun(i,u,p,U)
%
% INPUT:
%
% i - knot span ( from FindSpan() )
% u - parametric point
% p - spline degree
% U - knot sequence
%
% OUTPUT:
%
% N - Basis functions vector[p+1]
%
% Algorithm A2.2 from 'The NURBS BOOK' pg70.
% void basisfun(int i, double u, int p, double *U, double *N) {
% int j,r;
% double saved, temp;
i = i + 1;
% // work space
left = zeros(p+1,1); % double *left = (double*) mxMalloc((p+1)*sizeof(double));
right = zeros(p+1,1); % double *right = (double*) mxMalloc((p+1)*sizeof(double));
N(1) = 1; % N[0] = 1.0;
for j=1:p % for (j = 1; j <= p; j++) {
left(j+1) = u - U(i+1-j); % left[j] = u - U[i+1-j];
right(j+1) = U(i+j) - u; % right[j] = U[i+j] - u;
saved = 0; % saved = 0.0;
for r=0:j-1 % for (r = 0; r < j; r++) {
temp = N(r+1)/(right(r+2) + left(j-r+1)); % temp = N[r] / (right[r+1] + left[j-r]);
N(r+1) = saved + right(r+2)*temp; % N[r] = saved + right[r+1] * temp;
saved = left(j-r+1)*temp; % saved = left[j-r] * temp;
end % }
N(j+1) = saved; % N[j] = saved;
end % }
% mxFree(left);
% mxFree(right);
% }