X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?p=CreaPhase.git;a=blobdiff_plain;f=octave_packages%2Fnurbs-1.3.6%2Fcurvederiveval.m;fp=octave_packages%2Fnurbs-1.3.6%2Fcurvederiveval.m;h=6a43c09b4639d5ecf5016fa6ead20f739364ed28;hp=0000000000000000000000000000000000000000;hb=c880e8788dfc484bf23ce13fa2787f2c6bca4863;hpb=1705066eceaaea976f010f669ce8e972f3734b05 diff --git a/octave_packages/nurbs-1.3.6/curvederiveval.m b/octave_packages/nurbs-1.3.6/curvederiveval.m new file mode 100644 index 0000000..6a43c09 --- /dev/null +++ b/octave_packages/nurbs-1.3.6/curvederiveval.m @@ -0,0 +1,67 @@ +function ck = curvederiveval (n, p, U, P, u, d) +% +% CURVEDERIVEVAL: Compute the derivatives of a B-spline curve. +% +% usage: ck = curvederiveval (n, p, U, P, u, d) +% +% INPUT: +% +% n+1 = number of control points +% p = spline order +% U = knots +% P = control points +% u = evaluation point +% d = derivative order +% +% OUTPUT: +% +% ck (k+1) = curve differentiated k times +% +% Adaptation of algorithm A3.4 from the NURBS book, pg99 +% +% Copyright (C) 2009 Carlo de Falco +% Copyright (C) 2010 Rafael Vazquez +% +% This program is free software: you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation, either version 2 of the License, or +% (at your option) any later version. + +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program. If not, see . + + ck = zeros (d+1, 1); + du = min (d, p); + + span = findspan (n, p, u, U); + for ip=0:p + N(1:ip+1,ip+1) = basisfun (span, u, ip, U)'; + end + + pk = curvederivcpts (n, p, U, P, du, span-p, span); + + for k = 0:du + for j = 0:p-k + ck(k+1) = ck(k+1) + N(j+1,p-k+1)*pk(k+1,j+1); + end + end + +end + +%!test +%! k = [0 0 0 1 1 1]; +%! coefs(:,1) = [0;0;0;1]; +%! coefs(:,2) = [1;0;1;1]; +%! coefs(:,3) = [1;1;1;1]; +%! crv = nrbmak (coefs, k); +%! ck = curvederiveval (crv.number-1, crv.order-1, crv.knots, squeeze (crv.coefs(1,:,:)), 0.5, 2); +%! assert(ck, [0.75; 1; -2]); +%! ck = curvederiveval (crv.number-1, crv.order-1, crv.knots, squeeze (crv.coefs(2,:,:)), 0.5, 2); +%! assert(ck, [0.25; 1; 2]); +%! ck = curvederiveval (crv.number-1, crv.order-1, crv.knots, squeeze (crv.coefs(3,:,:)), 0.5, 2); +%! assert(ck, [0.75; 1; -2]);