-
Notifications
You must be signed in to change notification settings - Fork 6
/
nurbsweight.m
53 lines (53 loc) · 2.15 KB
/
nurbsweight.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
50
51
52
53
function B=nurbsweight(kn,degree,u)
% NURBSWEIGHT calculates NURBS basis functions using Equation 3.32 & 3.33
% B = NURBSWEIGHT(KN,D,U) returns a (d+1)x(d+1) matrix with elements
% defined by Equation 3.32 & 3.33, where KN is the knot vetor, D is the
% degree and U is the positoin along the position along the NURBS.
%
% Called by nurbs
%
% -------------------------------------------------------------------------
% Aircraft Geometry Toolbox v0.1.0, Andras Sobester 2014.
%
% Sobester, A, Forrester, A I J, "Aircraft Aerodynamic Design - Geometry
% and Optimization", Wiley, 2014.
% -------------------------------------------------------------------------
%
% Copyright 2014 A I J Forrester
%
% This program is free software: you can redistribute it and/or modify it
% under the terms of the GNU Lesser General Public License as published by
% the Free Software Foundation, either version 3 of the License, or any
% later version.
%
% This program is distributed in the hope that it will be useful, but
% WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
% General Public License for more details.
%
% You should have received a copy of the GNU General Public License and GNU
% Lesser General Public License along with this program. If not, see
% <http://www.gnu.org/licenses/>.
B=zeros(length(kn)-1,degree+1);
for k=1:degree+1
for i=1:length(kn)-(k)
if k==1 % intitialize recursive calculation at d=1
if (u>kn(i) && u<=kn(i+1)) || (u==kn(1) && i==degree+1)
B(i,k)=1;
else
B(i,k)=0;
end
else % d>1 basis functions
% catch denominator=0 cases
if kn(i+k-1)==kn(i) && kn(i+k)==kn(i+1)
B(i,k)=0;
elseif kn(i+k)==kn(i+1)
B(i,k)=((u-kn(i))/(kn(i+k-1)-kn(i)))*B(i,k-1);
elseif kn(i+k-1)==kn(i)
B(i,k)=((kn(i+k)-u)/(kn(i+k)-kn(i+1)))*B(i+1,k-1);
else
B(i,k)=((u-kn(i))/(kn(i+k-1)-kn(i)))*B(i,k-1)+((kn(i+k)-u)/(kn(i+k)-kn(i+1)))*B(i+1,k-1);
end
end
end
end