/usr/share/octave/packages/nurbs-1.3.13/nrbdeval.m is in octave-nurbs 1.3.13-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | function varargout = nrbdeval (nurbs, dnurbs, varargin)
% NRBDEVAL: Evaluation of the derivative and second derivatives of NURBS curve, surface or volume.
%
% [pnt, jac] = nrbdeval (crv, dcrv, tt)
% [pnt, jac] = nrbdeval (srf, dsrf, {tu tv})
% [pnt, jac] = nrbdeval (vol, dvol, {tu tv tw})
% [pnt, jac, hess] = nrbdeval (crv, dcrv, dcrv2, tt)
% [pnt, jac, hess] = nrbdeval (srf, dsrf, dsrf2, {tu tv})
% [pnt, jac, hess] = nrbdeval (vol, dvol, dvol2, {tu tv tw})
%
% INPUTS:
%
% crv, srf, vol - original NURBS curve, surface or volume.
% dcrv, dsrf, dvol - NURBS derivative representation of crv, srf
% or vol (see nrbderiv2)
% dcrv2, dsrf2, dvol2 - NURBS second derivative representation of crv,
% srf or vol (see nrbderiv2)
% tt - parametric evaluation points
% If the nurbs is a surface or a volume then tt is a cell
% {tu, tv} or {tu, tv, tw} are the parametric coordinates
%
% OUTPUT:
%
% pnt - evaluated points.
% jac - evaluated first derivatives (Jacobian).
% hess - evaluated second derivatives (Hessian).
%
% Copyright (C) 2000 Mark Spink
% Copyright (C) 2010 Carlo de Falco
% Copyright (C) 2010, 2011 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 3 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 <http://www.gnu.org/licenses/>.
if (nargin == 3)
tt = varargin{1};
elseif (nargin == 4)
dnurbs2 = varargin{1};
tt = varargin{2};
else
error ('nrbrdeval: wrong number of input parameters')
end
if (~isstruct(nurbs))
error('NURBS representation is not structure!');
end
if (~strcmp(nurbs.form,'B-NURBS'))
error('Not a recognised NURBS representation');
end
[cp,cw] = nrbeval(nurbs, tt);
if (iscell(nurbs.knots))
if (size(nurbs.knots,2) == 3)
% NURBS structure represents a volume
temp = cw(ones(3,1),:,:,:);
pnt = cp./temp;
[cup,cuw] = nrbeval (dnurbs{1}, tt);
tempu = cuw(ones(3,1),:,:,:);
jac{1} = (cup-tempu.*pnt)./temp;
[cvp,cvw] = nrbeval (dnurbs{2}, tt);
tempv = cvw(ones(3,1),:,:,:);
jac{2} = (cvp-tempv.*pnt)./temp;
[cwp,cww] = nrbeval (dnurbs{3}, tt);
tempw = cww(ones(3,1),:,:,:);
jac{3} = (cwp-tempw.*pnt)./temp;
% second derivatives
if (nargout == 3)
if (exist ('dnurbs2'))
[cuup, cuuw] = nrbeval (dnurbs2{1,1}, tt);
tempuu = cuuw(ones(3,1),:,:,:);
hess{1,1} = (cuup - (2*cup.*tempu + cp.*tempuu)./temp + 2*cp.*tempu.^2./temp.^2)./temp;
clear cuup cuuw tempuu
[cvvp, cvvw] = nrbeval (dnurbs2{2,2}, tt);
tempvv = cvvw(ones(3,1),:,:,:);
hess{2,2} = (cvvp - (2*cvp.*tempv + cp.*tempvv)./temp + 2*cp.*tempv.^2./temp.^2)./temp;
clear cvvp cvvw tempvv
[cwwp, cwww] = nrbeval (dnurbs2{3,3}, tt);
tempww = cwww(ones(3,1),:,:,:);
hess{3,3} = (cwwp - (2*cwp.*tempw + cp.*tempww)./temp + 2*cp.*tempw.^2./temp.^2)./temp;
clear cwwp cwww tempww
[cuvp, cuvw] = nrbeval (dnurbs2{1,2}, tt);
tempuv = cuvw(ones(3,1),:,:,:);
hess{1,2} = (cuvp - (cup.*tempv + cvp.*tempu + cp.*tempuv)./temp + 2*cp.*tempu.*tempv./temp.^2)./temp;
hess{2,1} = hess{1,2};
clear cuvp cuvw tempuv
[cuwp, cuww] = nrbeval (dnurbs2{1,3}, tt);
tempuw = cuww(ones(3,1),:,:,:);
hess{1,3} = (cuwp - (cup.*tempw + cwp.*tempu + cp.*tempuw)./temp + 2*cp.*tempu.*tempw./temp.^2)./temp;
hess{3,1} = hess{1,3};
clear cuwp cuww tempuw
[cvwp, cvww] = nrbeval (dnurbs2{2,3}, tt);
tempvw = cvww(ones(3,1),:,:,:);
hess{2,3} = (cvwp - (cvp.*tempw + cwp.*tempv + cp.*tempvw)./temp + 2*cp.*tempv.*tempw./temp.^2)./temp;
hess{3,2} = hess{2,3};
clear cvwp cvww tempvw
else
warning ('nrbdeval: dnurbs2 missing. The second derivative is not computed');
hess = [];
end
end
elseif (size(nurbs.knots,2) == 2)
% NURBS structure represents a surface
temp = cw(ones(3,1),:,:);
pnt = cp./temp;
[cup,cuw] = nrbeval (dnurbs{1}, tt);
tempu = cuw(ones(3,1),:,:);
jac{1} = (cup-tempu.*pnt)./temp;
[cvp,cvw] = nrbeval (dnurbs{2}, tt);
tempv = cvw(ones(3,1),:,:);
jac{2} = (cvp-tempv.*pnt)./temp;
% second derivatives
if (nargout == 3)
if (exist ('dnurbs2'))
[cuup, cuuw] = nrbeval (dnurbs2{1,1}, tt);
tempuu = cuuw(ones(3,1),:,:);
hess{1,1} = (cuup - (2*cup.*tempu + cp.*tempuu)./temp + 2*cp.*tempu.^2./temp.^2)./temp;
[cvvp, cvvw] = nrbeval (dnurbs2{2,2}, tt);
tempvv = cvvw(ones(3,1),:,:);
hess{2,2} = (cvvp - (2*cvp.*tempv + cp.*tempvv)./temp + 2*cp.*tempv.^2./temp.^2)./temp;
[cuvp, cuvw] = nrbeval (dnurbs2{1,2}, tt);
tempuv = cuvw(ones(3,1),:,:);
hess{1,2} = (cuvp - (cup.*tempv + cvp.*tempu + cp.*tempuv)./temp + 2*cp.*tempu.*tempv./temp.^2)./temp;
hess{2,1} = hess{1,2};
else
warning ('nrbdeval: dnurbs2 missing. The second derivative is not computed');
hess = [];
end
end
end
else
% NURBS is a curve
temp = cw(ones(3,1),:);
pnt = cp./temp;
% first derivative
[cup,cuw] = nrbeval (dnurbs,tt);
temp1 = cuw(ones(3,1),:);
jac = (cup-temp1.*pnt)./temp;
if (iscell (tt))
jac = {jac};
end
% second derivative
if (nargout == 3 && exist ('dnurbs2'))
[cuup,cuuw] = nrbeval (dnurbs2, tt);
temp2 = cuuw(ones(3,1),:);
hess = (cuup - (2*cup.*temp1 + cp.*temp2)./temp + 2*cp.*temp1.^2./temp.^2)./temp;
if (iscell (tt))
hess = {hess};
end
end
end
varargout{1} = pnt;
varargout{2} = jac;
if (nargout == 3)
varargout{3} = hess;
end
end
%!demo
%! crv = nrbtestcrv;
%! nrbplot(crv,48);
%! title('First derivatives along a test curve.');
%!
%! tt = linspace(0.0,1.0,9);
%!
%! dcrv = nrbderiv(crv);
%!
%! [p1, dp] = nrbdeval(crv,dcrv,tt);
%!
%! p2 = vecnorm(dp);
%!
%! hold on;
%! plot(p1(1,:),p1(2,:),'ro');
%! h = quiver(p1(1,:),p1(2,:),p2(1,:),p2(2,:),0);
%! set(h,'Color','black');
%! hold off;
%!demo
%! srf = nrbtestsrf;
%! p = nrbeval(srf,{linspace(0.0,1.0,20) linspace(0.0,1.0,20)});
%! h = surf(squeeze(p(1,:,:)),squeeze(p(2,:,:)),squeeze(p(3,:,:)));
%! set(h,'FaceColor','blue','EdgeColor','blue');
%! title('First derivatives over a test surface.');
%!
%! npts = 5;
%! tt = linspace(0.0,1.0,npts);
%! dsrf = nrbderiv(srf);
%!
%! [p1, dp] = nrbdeval(srf, dsrf, {tt, tt});
%!
%! up2 = vecnorm(dp{1});
%! vp2 = vecnorm(dp{2});
%!
%! hold on;
%! plot3(p1(1,:),p1(2,:),p1(3,:),'ro');
%! h1 = quiver3(p1(1,:),p1(2,:),p1(3,:),up2(1,:),up2(2,:),up2(3,:));
%! h2 = quiver3(p1(1,:),p1(2,:),p1(3,:),vp2(1,:),vp2(2,:),vp2(3,:));
%! set(h1,'Color','black');
%! set(h2,'Color','black');
%!
%! hold off;
%!test
%! knots{1} = [0 0 0 1 1 1];
%! knots{2} = [0 0 0 .5 1 1 1];
%! knots{3} = [0 0 0 0 1 1 1 1];
%! cx = [0 0.5 1]; nx = length(cx);
%! cy = [0 0.25 0.75 1]; ny = length(cy);
%! cz = [0 1/3 2/3 1]; nz = length(cz);
%! coefs(1,:,:,:) = repmat(reshape(cx,nx,1,1),[1 ny nz]);
%! coefs(2,:,:,:) = repmat(reshape(cy,1,ny,1),[nx 1 nz]);
%! coefs(3,:,:,:) = repmat(reshape(cz,1,1,nz),[nx ny 1]);
%! coefs(4,:,:,:) = 1;
%! nurbs = nrbmak(coefs, knots);
%! x = rand(5,1); y = rand(5,1); z = rand(5,1);
%! tt = [x y z]';
%! ders = nrbderiv(nurbs);
%! [points,jac] = nrbdeval(nurbs,ders,tt);
%! assert(points,tt,1e-10)
%! assert(jac{1}(1,:,:),ones(size(jac{1}(1,:,:))),1e-12)
%! assert(jac{2}(2,:,:),ones(size(jac{2}(2,:,:))),1e-12)
%! assert(jac{3}(3,:,:),ones(size(jac{3}(3,:,:))),1e-12)
%!
%!test
%! knots{1} = [0 0 0 1 1 1];
%! knots{2} = [0 0 0 0 1 1 1 1];
%! knots{3} = [0 0 0 1 1 1];
%! cx = [0 0 1]; nx = length(cx);
%! cy = [0 0 0 1]; ny = length(cy);
%! cz = [0 0.5 1]; nz = length(cz);
%! coefs(1,:,:,:) = repmat(reshape(cx,nx,1,1),[1 ny nz]);
%! coefs(2,:,:,:) = repmat(reshape(cy,1,ny,1),[nx 1 nz]);
%! coefs(3,:,:,:) = repmat(reshape(cz,1,1,nz),[nx ny 1]);
%! coefs(4,:,:,:) = 1;
%! coefs = coefs([2 1 3 4],:,:,:);
%! nurbs = nrbmak(coefs, knots);
%! x = rand(5,1); y = rand(5,1); z = rand(5,1);
%! tt = [x y z]';
%! dnurbs = nrbderiv(nurbs);
%! [points, jac] = nrbdeval(nurbs,dnurbs,tt);
%! assert(points,[y.^3 x.^2 z]',1e-10);
%! assert(jac{2}(1,:,:),3*y'.^2,1e-12)
%! assert(jac{1}(2,:,:),2*x',1e-12)
%! assert(jac{3}(3,:,:),ones(size(z')),1e-12)
|