]> Creatis software - CreaPhase.git/blob - octave_packages/nurbs-1.3.6/surfderivcpts.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / nurbs-1.3.6 / surfderivcpts.m
1 function pkl = surfderivcpts (n, p, U, m, q, V, P, d, r1, r2, s1, s2) 
2 %
3 % SURFDERIVCPTS: Compute control points of n-th derivatives of a NURBS surface.
4
5 % usage: pkl = surfderivcpts (n, p, U, m, q, V, P, d) 
6 %
7 %  INPUT: 
8 %
9 %        n+1, m+1 = number of control points
10 %        p, q     = spline order
11 %        U, V     = knots
12 %        P        = control points
13 %        d        = derivative order
14 %
15 %  OUTPUT:
16 %
17 %        pkl (k+1, l+1, i+1, j+1) = i,jth control point
18 %                                   of the surface differentiated k
19 %                                   times in the u direction and l
20 %                                   times in the v direction
21 %
22 % Adaptation of algorithm A3.7 from the NURBS book, pg114
23 %
24 %    Copyright (C) 2009 Carlo de Falco
25 %
26 %    This program is free software: you can redistribute it and/or modify
27 %    it under the terms of the GNU General Public License as published by
28 %    the Free Software Foundation, either version 2 of the License, or
29 %    (at your option) any later version.
30
31 %    This program is distributed in the hope that it will be useful,
32 %    but WITHOUT ANY WARRANTY; without even the implied warranty of
33 %    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
34 %    GNU General Public License for more details.
35 %
36 %    You should have received a copy of the GNU General Public License
37 %    along with this program.  If not, see <http://www.gnu.org/licenses/>.
38   
39   if (nargin <= 8)
40     r1 = 0; r2 = n;
41     s1 = 0; s2 = m;
42   end
43   r = r2-r1;
44   s = s2-s1;
45
46   du = min (d, p);   dv = min (d, q); 
47
48   for j=s1:s2
49     temp = curvederivcpts (n, p, U, P(:,j+1:end), du, r1, r2);
50     for k=0:du
51       for i=0:r-k
52        pkl (k+1, 1, i+1, j-s1+1) = temp (k+1, i+1);
53       end
54     end
55   end
56   
57   for k=0:du
58     for i=0:r-k
59       dd = min (d-k, dv);
60       temp = curvederivcpts (m, q, V(s1+1:end), pkl(k+1, 1, i+1, :),  ...
61                              dd, 0, s);
62       for l=1:dd
63        for j=0:s-l
64         pkl (k+1, l+1, i+1, j+1) = temp (l+1, j+1);
65        end
66       end
67     end
68   end
69
70 end
71
72 %!test
73 %! coefs = cat(3,[0 0; 0 1],[1 1; 0 1]);
74 %! knots = {[0 0 1 1]  [0 0 1 1]};
75 %! plane = nrbmak(coefs,knots);
76 %! pkl = surfderivcpts (plane.number(1)-1, plane.order(1)-1,...
77 %!                       plane.knots{1}, plane.number(2)-1,...
78 %!                       plane.order(2)-1, plane.knots{2}, ...
79 %!                       squeeze (plane.coefs(1,:,:)), 1);