]> Creatis software - CreaPhase.git/blob - octave_packages/nurbs-1.3.6/curvederiveval.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / nurbs-1.3.6 / curvederiveval.m
1 function ck = curvederiveval (n, p, U, P, u, d) 
2 %
3 % CURVEDERIVEVAL: Compute the derivatives of a B-spline curve.
4
5 % usage: ck = curvederiveval (n, p, U, P, u, d) 
6 %
7 %  INPUT: 
8 %
9 %        n+1 = number of control points
10 %        p   = spline order
11 %        U   = knots
12 %        P   = control points
13 %        u   = evaluation point
14 %        d   = derivative order
15 %
16 %  OUTPUT:
17 %
18 %        ck (k+1) =  curve differentiated k times
19 %
20 % Adaptation of algorithm A3.4 from the NURBS book, pg99
21 %
22 %    Copyright (C) 2009 Carlo de Falco
23 %    Copyright (C) 2010 Rafael Vazquez
24 %
25 %    This program is free software: you can redistribute it and/or modify
26 %    it under the terms of the GNU General Public License as published by
27 %    the Free Software Foundation, either version 2 of the License, or
28 %    (at your option) any later version.
29
30 %    This program is distributed in the hope that it will be useful,
31 %    but WITHOUT ANY WARRANTY; without even the implied warranty of
32 %    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
33 %    GNU General Public License for more details.
34 %
35 %    You should have received a copy of the GNU General Public License
36 %    along with this program.  If not, see <http://www.gnu.org/licenses/>.
37
38   ck = zeros (d+1, 1);
39   du = min (d, p);   
40
41   span = findspan (n, p, u, U);
42   for ip=0:p
43       N(1:ip+1,ip+1) = basisfun (span, u, ip, U)';
44   end
45     
46   pk = curvederivcpts (n, p, U, P, du, span-p, span);
47
48   for k = 0:du
49     for j = 0:p-k
50       ck(k+1) = ck(k+1) + N(j+1,p-k+1)*pk(k+1,j+1);
51     end
52   end
53   
54 end
55
56 %!test
57 %! k = [0 0 0 1 1 1];
58 %! coefs(:,1) = [0;0;0;1];
59 %! coefs(:,2) = [1;0;1;1];
60 %! coefs(:,3) = [1;1;1;1];
61 %! crv = nrbmak (coefs, k);
62 %! ck = curvederiveval (crv.number-1, crv.order-1, crv.knots, squeeze (crv.coefs(1,:,:)), 0.5, 2);
63 %! assert(ck, [0.75; 1; -2]);
64 %! ck = curvederiveval (crv.number-1, crv.order-1, crv.knots, squeeze (crv.coefs(2,:,:)), 0.5, 2);
65 %! assert(ck, [0.25; 1; 2]);
66 %! ck = curvederiveval (crv.number-1, crv.order-1, crv.knots, squeeze (crv.coefs(3,:,:)), 0.5, 2);
67 %! assert(ck, [0.75; 1; -2]);