]> Creatis software - CreaPhase.git/blob - octave_packages/nurbs-1.3.6/bspderiv.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / nurbs-1.3.6 / bspderiv.m
1 function [dc,dk] = bspderiv(d,c,k)
2
3 % BSPDERIV:  B-Spline derivative.
4
5 %  MATLAB SYNTAX:
6
7 %         [dc,dk] = bspderiv(d,c,k)
8 %  
9 %  INPUT:
10
11 %    d - degree of the B-Spline
12 %    c - control points          double  matrix(mc,nc)
13 %    k - knot sequence           double  vector(nk)
14
15 %  OUTPUT:
16
17 %    dc - control points of the derivative     double  matrix(mc,nc)
18 %    dk - knot sequence of the derivative      double  vector(nk)
19
20 %  Modified version of Algorithm A3.3 from 'The NURBS BOOK' pg98.
21 %
22 %    Copyright (C) 2000 Mark Spink, 2007 Daniel Claxton
23 %
24 %    This program is free software: you can redistribute it and/or modify
25 %    it under the terms of the GNU General Public License as published by
26 %    the Free Software Foundation, either version 2 of the License, or
27 %    (at your option) any later version.
28
29 %    This program is distributed in the hope that it will be useful,
30 %    but WITHOUT ANY WARRANTY; without even the implied warranty of
31 %    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
32 %    GNU General Public License for more details.
33 %
34 %    You should have received a copy of the GNU General Public License
35 %    along with this program.  If not, see <http://www.gnu.org/licenses/>.
36
37 [mc,nc] = size(c);
38 nk = numel(k);
39                                                      %
40                                                      % int bspderiv(int d, double *c, int mc, int nc, double *k, int nk, double *dc,
41                                                      %              double *dk)
42                                                      % {
43                                                      %   int ierr = 0;
44                                                      %   int i, j, tmp;
45                                                      %
46                                                      %   // control points
47                                                      %   double **ctrl = vec2mat(c,mc,nc);
48                                                      %
49                                                      %   // control points of the derivative
50 dc = zeros(mc,nc-1);                                 %   double **dctrl = vec2mat(dc,mc,nc-1);
51                                                      %
52 for i=0:nc-2                                         %   for (i = 0; i < nc-1; i++) {
53    tmp = d / (k(i+d+2) - k(i+2));                    %     tmp = d / (k[i+d+1] - k[i+1]);
54    for j=0:mc-1                                      %     for (j = 0; j < mc; j++) {
55        dc(j+1,i+1) = tmp*(c(j+1,i+2) - c(j+1,i+1));  %       dctrl[i][j] = tmp * (ctrl[i+1][j] - ctrl[i][j]);
56    end                                               %     }
57 end                                                  %   }
58                                                      %
59 dk = zeros(1,nk-2);                                  %   j = 0;
60 for i=1:nk-2                                         %   for (i = 1; i < nk-1; i++)
61    dk(i) = k(i+1);                                   %     dk[j++] = k[i];
62 end                                                  %
63                                                      %   freevec2mat(dctrl);
64                                                      %   freevec2mat(ctrl);
65                                                      %
66                                                      %   return ierr;
67 end                                                  % }