PageRenderTime 54ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/R2009-06-07/extra/nurbs/inst/bspderiv.m

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