]> Creatis software - CreaPhase.git/blob - octave_packages/nurbs-1.3.6/surfderiveval.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / nurbs-1.3.6 / surfderiveval.m
1 function skl = surfderiveval (n, p, U, m, q, V, P, u, v, d) 
2 %
3 % SURFDERIVEVAL: Compute the derivatives of a B-spline surface
4
5 % usage: skl = surfderiveval (n, p, U, m, q, V, P, u, v, 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 %        u,v      = evaluation points
14 %        d        = derivative order
15 %
16 %  OUTPUT:
17 %
18 %        skl (k+1, l+1) =  surface differentiated k
19 %                          times in the u direction and l
20 %                          times in the v direction
21 %
22 % Adaptation of algorithm A3.8 from the NURBS book, pg115
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   skl = zeros (d+1, d+1);
40   du = min (d, p);   
41   dv = min (d, q);   
42
43   uspan = findspan (n, p, u, U);
44   for ip=0:p
45       Nu(1:ip+1,ip+1) = basisfun (uspan, u, ip, U)';
46   end
47   
48   vspan = findspan (m, q, v, V);
49   for ip=0:q
50       Nv(1:ip+1,ip+1) = basisfun (vspan, v, ip, V)';
51   end
52
53   pkl = surfderivcpts (n, p, U, m, q, V, P, d, uspan-p, uspan,  ...
54                        vspan-q, vspan);
55
56   for k = 0:du
57     dd = min (d-k, dv);
58     for l = 0:dd
59       skl(k+1,l+1) =0;
60       for i=0:q-l
61        tmp = 0;
62        for j = 0:p-k
63         tmp = tmp + Nu(j+1,p-k+1) * pkl(k+1,l+1,j+1,i+1);
64        end
65        skl(k+1,l+1) = skl(k+1,l+1) + Nv(i+1,q-l+1)*tmp;
66       end
67     end
68   end
69   
70 end
71
72 %!shared srf
73 %!test
74 %! k = [0 0 0 1 1 1];
75 %! c = [0 1/2 1];
76 %! [coef(2,:,:), coef(1,:,:)] = meshgrid (c, c);
77 %! srf = nrbmak (coef, {k, k});
78 %! skl = surfderiveval (srf.number(1)-1, ...
79 %!                      srf.order(1)-1, ...
80 %!                      srf.knots{1}, ...
81 %!                      srf.number(2)-1, ...
82 %!                      srf.order(2)-1, ...
83 %!                      srf.knots{2},...
84 %!                      squeeze(srf.coefs(1,:,:)), .5, .5, 1) ;
85 %! assert (skl, [.5 0; 1 0])
86 %!test
87 %! srf = nrbkntins (srf, {[], rand(1,2)});
88 %! skl = surfderiveval (srf.number(1)-1,... 
89 %!                      srf.order(1)-1, ...
90 %!                      srf.knots{1},...
91 %!                      srf.number(2)-1,... 
92 %!                      srf.order(2)-1, ...
93 %!                      srf.knots{2},...
94 %!                      squeeze(srf.coefs(1,:,:)), .5, .5, 1) ;
95 %! assert (skl, [.5 0; 1 0], 100*eps)