annotate extra/nurbs/inst/nrbdeval.m @ 12567:560f9cfb5db9 octave-forge

Consistent output in the univariate case
author rafavzqz
date Wed, 11 Mar 2015 10:06:32 +0000
parents 37d08939bb7b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8215
613633634c8e New version to compute the second derivatives
rafavzqz
parents: 8214
diff changeset
1 function varargout = nrbdeval (nurbs, dnurbs, varargin)
5552
6bc116f6bbc3 cleanup
cdf
parents: 5224
diff changeset
2
8215
613633634c8e New version to compute the second derivatives
rafavzqz
parents: 8214
diff changeset
3 % NRBDEVAL: Evaluation of the derivative and second derivatives of NURBS curve, surface or volume.
5552
6bc116f6bbc3 cleanup
cdf
parents: 5224
diff changeset
4 %
8215
613633634c8e New version to compute the second derivatives
rafavzqz
parents: 8214
diff changeset
5 % [pnt, jac] = nrbdeval (crv, dcrv, tt)
613633634c8e New version to compute the second derivatives
rafavzqz
parents: 8214
diff changeset
6 % [pnt, jac] = nrbdeval (srf, dsrf, {tu tv})
613633634c8e New version to compute the second derivatives
rafavzqz
parents: 8214
diff changeset
7 % [pnt, jac] = nrbdeval (vol, dvol, {tu tv tw})
613633634c8e New version to compute the second derivatives
rafavzqz
parents: 8214
diff changeset
8 % [pnt, jac, hess] = nrbdeval (crv, dcrv, dcrv2, tt)
613633634c8e New version to compute the second derivatives
rafavzqz
parents: 8214
diff changeset
9 % [pnt, jac, hess] = nrbdeval (srf, dsrf, dsrf2, {tu tv})
613633634c8e New version to compute the second derivatives
rafavzqz
parents: 8214
diff changeset
10 % [pnt, jac, hess] = nrbdeval (vol, dvol, {tu tv tw})
5552
6bc116f6bbc3 cleanup
cdf
parents: 5224
diff changeset
11 %
6bc116f6bbc3 cleanup
cdf
parents: 5224
diff changeset
12 % INPUTS:
6bc116f6bbc3 cleanup
cdf
parents: 5224
diff changeset
13 %
8215
613633634c8e New version to compute the second derivatives
rafavzqz
parents: 8214
diff changeset
14 % crv, srf, vol - original NURBS curve, surface or volume.
613633634c8e New version to compute the second derivatives
rafavzqz
parents: 8214
diff changeset
15 % dcrv, dsrf, dvol - NURBS derivative representation of crv, srf
613633634c8e New version to compute the second derivatives
rafavzqz
parents: 8214
diff changeset
16 % or vol (see nrbderiv2)
613633634c8e New version to compute the second derivatives
rafavzqz
parents: 8214
diff changeset
17 % dcrv2, dsrf2, dvol2 - NURBS second derivative representation of crv,
613633634c8e New version to compute the second derivatives
rafavzqz
parents: 8214
diff changeset
18 % srf or vol (see nrbderiv2)
5552
6bc116f6bbc3 cleanup
cdf
parents: 5224
diff changeset
19 % tt - parametric evaluation points
6910
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
20 % If the nurbs is a surface or a volume then tt is a cell
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
21 % {tu, tv} or {tu, tv, tw} are the parametric coordinates
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
22 %
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
23 % OUTPUT:
5552
6bc116f6bbc3 cleanup
cdf
parents: 5224
diff changeset
24 %
6bc116f6bbc3 cleanup
cdf
parents: 5224
diff changeset
25 % pnt - evaluated points.
6bc116f6bbc3 cleanup
cdf
parents: 5224
diff changeset
26 % jac - evaluated first derivatives (Jacobian).
8215
613633634c8e New version to compute the second derivatives
rafavzqz
parents: 8214
diff changeset
27 % hess - evaluated second derivatives (Hessian).
6910
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
28 %
7114
ec90474d70bb some copyright text changes
cdf
parents: 6910
diff changeset
29 % Copyright (C) 2000 Mark Spink
ec90474d70bb some copyright text changes
cdf
parents: 6910
diff changeset
30 % Copyright (C) 2010 Carlo de Falco
8215
613633634c8e New version to compute the second derivatives
rafavzqz
parents: 8214
diff changeset
31 % Copyright (C) 2010, 2011 Rafael Vazquez
6910
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
32 %
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
33 % This program is free software: you can redistribute it and/or modify
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
34 % it under the terms of the GNU General Public License as published by
11634
37d08939bb7b apply changes requested by David
cdf
parents: 8286
diff changeset
35 % the Free Software Foundation, either version 3 of the License, or
6910
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
36 % (at your option) any later version.
5552
6bc116f6bbc3 cleanup
cdf
parents: 5224
diff changeset
37
6910
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
38 % This program is distributed in the hope that it will be useful,
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
39 % but WITHOUT ANY WARRANTY; without even the implied warranty of
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
40 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
41 % GNU General Public License for more details.
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
42 %
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
43 % You should have received a copy of the GNU General Public License
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
44 % along with this program. If not, see <http://www.gnu.org/licenses/>.
5552
6bc116f6bbc3 cleanup
cdf
parents: 5224
diff changeset
45
8215
613633634c8e New version to compute the second derivatives
rafavzqz
parents: 8214
diff changeset
46 if (nargin == 3)
613633634c8e New version to compute the second derivatives
rafavzqz
parents: 8214
diff changeset
47 tt = varargin{1};
613633634c8e New version to compute the second derivatives
rafavzqz
parents: 8214
diff changeset
48 elseif (nargin == 4)
613633634c8e New version to compute the second derivatives
rafavzqz
parents: 8214
diff changeset
49 dnurbs2 = varargin{1};
613633634c8e New version to compute the second derivatives
rafavzqz
parents: 8214
diff changeset
50 tt = varargin{2};
613633634c8e New version to compute the second derivatives
rafavzqz
parents: 8214
diff changeset
51 else
613633634c8e New version to compute the second derivatives
rafavzqz
parents: 8214
diff changeset
52 error ('nrbrdeval: wrong number of input parameters')
613633634c8e New version to compute the second derivatives
rafavzqz
parents: 8214
diff changeset
53 end
613633634c8e New version to compute the second derivatives
rafavzqz
parents: 8214
diff changeset
54
8214
8c1ab65f1d79 Unimportant changes
rafavzqz
parents: 7114
diff changeset
55 if (~isstruct(nurbs))
5552
6bc116f6bbc3 cleanup
cdf
parents: 5224
diff changeset
56 error('NURBS representation is not structure!');
6bc116f6bbc3 cleanup
cdf
parents: 5224
diff changeset
57 end
6bc116f6bbc3 cleanup
cdf
parents: 5224
diff changeset
58
8214
8c1ab65f1d79 Unimportant changes
rafavzqz
parents: 7114
diff changeset
59 if (~strcmp(nurbs.form,'B-NURBS'))
5552
6bc116f6bbc3 cleanup
cdf
parents: 5224
diff changeset
60 error('Not a recognised NURBS representation');
6bc116f6bbc3 cleanup
cdf
parents: 5224
diff changeset
61 end
6bc116f6bbc3 cleanup
cdf
parents: 5224
diff changeset
62
8215
613633634c8e New version to compute the second derivatives
rafavzqz
parents: 8214
diff changeset
63 [cp,cw] = nrbeval(nurbs, tt);
5552
6bc116f6bbc3 cleanup
cdf
parents: 5224
diff changeset
64
8214
8c1ab65f1d79 Unimportant changes
rafavzqz
parents: 7114
diff changeset
65 if (iscell(nurbs.knots))
8c1ab65f1d79 Unimportant changes
rafavzqz
parents: 7114
diff changeset
66 if (size(nurbs.knots,2) == 3)
6910
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
67 % NURBS structure represents a volume
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
68 temp = cw(ones(3,1),:,:,:);
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
69 pnt = cp./temp;
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
70
8214
8c1ab65f1d79 Unimportant changes
rafavzqz
parents: 7114
diff changeset
71 [cup,cuw] = nrbeval (dnurbs{1}, tt);
6910
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
72 tempu = cuw(ones(3,1),:,:,:);
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
73 jac{1} = (cup-tempu.*pnt)./temp;
5552
6bc116f6bbc3 cleanup
cdf
parents: 5224
diff changeset
74
8214
8c1ab65f1d79 Unimportant changes
rafavzqz
parents: 7114
diff changeset
75 [cvp,cvw] = nrbeval (dnurbs{2}, tt);
6910
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
76 tempv = cvw(ones(3,1),:,:,:);
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
77 jac{2} = (cvp-tempv.*pnt)./temp;
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
78
8214
8c1ab65f1d79 Unimportant changes
rafavzqz
parents: 7114
diff changeset
79 [cwp,cww] = nrbeval (dnurbs{3}, tt);
6910
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
80 tempw = cww(ones(3,1),:,:,:);
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
81 jac{3} = (cwp-tempw.*pnt)./temp;
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
82
8286
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
83 % second derivatives
8215
613633634c8e New version to compute the second derivatives
rafavzqz
parents: 8214
diff changeset
84 if (nargout == 3)
8286
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
85 if (exist ('dnurbs2'))
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
86 [cuup, cuuw] = nrbeval (dnurbs2{1,1}, tt);
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
87 tempuu = cuuw(ones(3,1),:,:,:);
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
88 hess{1,1} = (cuup - (2*cup.*tempu + cp.*tempuu)./temp + 2*cp.*tempu.^2./temp.^2)./temp;
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
89 clear cuup cuuw tempuu
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
90
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
91 [cvvp, cvvw] = nrbeval (dnurbs2{2,2}, tt);
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
92 tempvv = cvvw(ones(3,1),:,:,:);
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
93 hess{2,2} = (cvvp - (2*cvp.*tempv + cp.*tempvv)./temp + 2*cp.*tempv.^2./temp.^2)./temp;
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
94 clear cvvp cvvw tempvv
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
95
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
96 [cwwp, cwww] = nrbeval (dnurbs2{3,3}, tt);
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
97 tempww = cwww(ones(3,1),:,:,:);
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
98 hess{3,3} = (cwwp - (2*cwp.*tempw + cp.*tempww)./temp + 2*cp.*tempw.^2./temp.^2)./temp;
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
99 clear cwwp cwww tempww
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
100
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
101 [cuvp, cuvw] = nrbeval (dnurbs2{1,2}, tt);
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
102 tempuv = cuvw(ones(3,1),:,:,:);
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
103 hess{1,2} = (cuvp - (cup.*tempv + cvp.*tempu + cp.*tempuv)./temp + 2*cp.*tempu.*tempv./temp.^2)./temp;
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
104 hess{2,1} = hess{1,2};
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
105 clear cuvp cuvw tempuv
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
106
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
107 [cuwp, cuww] = nrbeval (dnurbs2{1,3}, tt);
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
108 tempuw = cuww(ones(3,1),:,:,:);
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
109 hess{1,3} = (cuwp - (cup.*tempw + cwp.*tempu + cp.*tempuw)./temp + 2*cp.*tempu.*tempw./temp.^2)./temp;
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
110 hess{3,1} = hess{1,3};
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
111 clear cuwp cuww tempuw
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
112
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
113 [cvwp, cvww] = nrbeval (dnurbs2{2,3}, tt);
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
114 tempvw = cvww(ones(3,1),:,:,:);
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
115 hess{2,3} = (cvwp - (cvp.*tempw + cwp.*tempv + cp.*tempvw)./temp + 2*cp.*tempv.*tempw./temp.^2)./temp;
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
116 hess{3,2} = hess{2,3};
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
117 clear cvwp cvww tempvw
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
118 else
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
119 warning ('nrbdeval: dnurbs2 missing. The second derivative is not computed');
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
120 hess = [];
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
121 end
8215
613633634c8e New version to compute the second derivatives
rafavzqz
parents: 8214
diff changeset
122 end
613633634c8e New version to compute the second derivatives
rafavzqz
parents: 8214
diff changeset
123
8214
8c1ab65f1d79 Unimportant changes
rafavzqz
parents: 7114
diff changeset
124 elseif (size(nurbs.knots,2) == 2)
6910
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
125 % NURBS structure represents a surface
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
126 temp = cw(ones(3,1),:,:);
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
127 pnt = cp./temp;
5552
6bc116f6bbc3 cleanup
cdf
parents: 5224
diff changeset
128
8214
8c1ab65f1d79 Unimportant changes
rafavzqz
parents: 7114
diff changeset
129 [cup,cuw] = nrbeval (dnurbs{1}, tt);
6910
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
130 tempu = cuw(ones(3,1),:,:);
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
131 jac{1} = (cup-tempu.*pnt)./temp;
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
132
8214
8c1ab65f1d79 Unimportant changes
rafavzqz
parents: 7114
diff changeset
133 [cvp,cvw] = nrbeval (dnurbs{2}, tt);
6910
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
134 tempv = cvw(ones(3,1),:,:);
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
135 jac{2} = (cvp-tempv.*pnt)./temp;
5552
6bc116f6bbc3 cleanup
cdf
parents: 5224
diff changeset
136
8215
613633634c8e New version to compute the second derivatives
rafavzqz
parents: 8214
diff changeset
137 % second derivatives
8286
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
138 if (nargout == 3)
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
139 if (exist ('dnurbs2'))
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
140 [cuup, cuuw] = nrbeval (dnurbs2{1,1}, tt);
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
141 tempuu = cuuw(ones(3,1),:,:);
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
142 hess{1,1} = (cuup - (2*cup.*tempu + cp.*tempuu)./temp + 2*cp.*tempu.^2./temp.^2)./temp;
8215
613633634c8e New version to compute the second derivatives
rafavzqz
parents: 8214
diff changeset
143
8286
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
144 [cvvp, cvvw] = nrbeval (dnurbs2{2,2}, tt);
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
145 tempvv = cvvw(ones(3,1),:,:);
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
146 hess{2,2} = (cvvp - (2*cvp.*tempv + cp.*tempvv)./temp + 2*cp.*tempv.^2./temp.^2)./temp;
8215
613633634c8e New version to compute the second derivatives
rafavzqz
parents: 8214
diff changeset
147
8286
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
148 [cuvp, cuvw] = nrbeval (dnurbs2{1,2}, tt);
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
149 tempuv = cuvw(ones(3,1),:,:);
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
150 hess{1,2} = (cuvp - (cup.*tempv + cvp.*tempu + cp.*tempuv)./temp + 2*cp.*tempu.*tempv./temp.^2)./temp;
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
151 hess{2,1} = hess{1,2};
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
152 else
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
153 warning ('nrbdeval: dnurbs2 missing. The second derivative is not computed');
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
154 hess = [];
d98e2ac94429 Second derivatives and tests, also for volumes
rafavzqz
parents: 8215
diff changeset
155 end
8215
613633634c8e New version to compute the second derivatives
rafavzqz
parents: 8214
diff changeset
156 end
613633634c8e New version to compute the second derivatives
rafavzqz
parents: 8214
diff changeset
157
6910
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
158 end
5552
6bc116f6bbc3 cleanup
cdf
parents: 5224
diff changeset
159 else
6bc116f6bbc3 cleanup
cdf
parents: 5224
diff changeset
160
6bc116f6bbc3 cleanup
cdf
parents: 5224
diff changeset
161 % NURBS is a curve
6bc116f6bbc3 cleanup
cdf
parents: 5224
diff changeset
162 temp = cw(ones(3,1),:);
6bc116f6bbc3 cleanup
cdf
parents: 5224
diff changeset
163 pnt = cp./temp;
6bc116f6bbc3 cleanup
cdf
parents: 5224
diff changeset
164
6bc116f6bbc3 cleanup
cdf
parents: 5224
diff changeset
165 % first derivative
8214
8c1ab65f1d79 Unimportant changes
rafavzqz
parents: 7114
diff changeset
166 [cup,cuw] = nrbeval (dnurbs,tt);
5552
6bc116f6bbc3 cleanup
cdf
parents: 5224
diff changeset
167 temp1 = cuw(ones(3,1),:);
6bc116f6bbc3 cleanup
cdf
parents: 5224
diff changeset
168 jac = (cup-temp1.*pnt)./temp;
12567
560f9cfb5db9 Consistent output in the univariate case
rafavzqz
parents: 11634
diff changeset
169 if (iscell (tt))
560f9cfb5db9 Consistent output in the univariate case
rafavzqz
parents: 11634
diff changeset
170 jac = {jac};
560f9cfb5db9 Consistent output in the univariate case
rafavzqz
parents: 11634
diff changeset
171 end
5552
6bc116f6bbc3 cleanup
cdf
parents: 5224
diff changeset
172
8215
613633634c8e New version to compute the second derivatives
rafavzqz
parents: 8214
diff changeset
173 % second derivative
613633634c8e New version to compute the second derivatives
rafavzqz
parents: 8214
diff changeset
174 if (nargout == 3 && exist ('dnurbs2'))
613633634c8e New version to compute the second derivatives
rafavzqz
parents: 8214
diff changeset
175 [cuup,cuuw] = nrbeval (dnurbs2, tt);
613633634c8e New version to compute the second derivatives
rafavzqz
parents: 8214
diff changeset
176 temp2 = cuuw(ones(3,1),:);
613633634c8e New version to compute the second derivatives
rafavzqz
parents: 8214
diff changeset
177 hess = (cuup - (2*cup.*temp1 + cp.*temp2)./temp + 2*cp.*temp1.^2./temp.^2)./temp;
12567
560f9cfb5db9 Consistent output in the univariate case
rafavzqz
parents: 11634
diff changeset
178 if (iscell (tt))
560f9cfb5db9 Consistent output in the univariate case
rafavzqz
parents: 11634
diff changeset
179 hess = {hess};
560f9cfb5db9 Consistent output in the univariate case
rafavzqz
parents: 11634
diff changeset
180 end
8215
613633634c8e New version to compute the second derivatives
rafavzqz
parents: 8214
diff changeset
181 end
12567
560f9cfb5db9 Consistent output in the univariate case
rafavzqz
parents: 11634
diff changeset
182
8215
613633634c8e New version to compute the second derivatives
rafavzqz
parents: 8214
diff changeset
183 end
613633634c8e New version to compute the second derivatives
rafavzqz
parents: 8214
diff changeset
184
613633634c8e New version to compute the second derivatives
rafavzqz
parents: 8214
diff changeset
185 varargout{1} = pnt;
613633634c8e New version to compute the second derivatives
rafavzqz
parents: 8214
diff changeset
186 varargout{2} = jac;
613633634c8e New version to compute the second derivatives
rafavzqz
parents: 8214
diff changeset
187 if (nargout == 3)
613633634c8e New version to compute the second derivatives
rafavzqz
parents: 8214
diff changeset
188 varargout{3} = hess;
5552
6bc116f6bbc3 cleanup
cdf
parents: 5224
diff changeset
189 end
6bc116f6bbc3 cleanup
cdf
parents: 5224
diff changeset
190
6910
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
191 end
5552
6bc116f6bbc3 cleanup
cdf
parents: 5224
diff changeset
192
6910
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
193 %!demo
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
194 %! crv = nrbtestcrv;
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
195 %! nrbplot(crv,48);
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
196 %! title('First derivatives along a test curve.');
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
197 %!
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
198 %! tt = linspace(0.0,1.0,9);
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
199 %!
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
200 %! dcrv = nrbderiv(crv);
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
201 %!
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
202 %! [p1, dp] = nrbdeval(crv,dcrv,tt);
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
203 %!
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
204 %! p2 = vecnorm(dp);
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
205 %!
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
206 %! hold on;
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
207 %! plot(p1(1,:),p1(2,:),'ro');
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
208 %! h = quiver(p1(1,:),p1(2,:),p2(1,:),p2(2,:),0);
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
209 %! set(h,'Color','black');
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
210 %! hold off;
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
211
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
212 %!demo
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
213 %! srf = nrbtestsrf;
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
214 %! p = nrbeval(srf,{linspace(0.0,1.0,20) linspace(0.0,1.0,20)});
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
215 %! h = surf(squeeze(p(1,:,:)),squeeze(p(2,:,:)),squeeze(p(3,:,:)));
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
216 %! set(h,'FaceColor','blue','EdgeColor','blue');
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
217 %! title('First derivatives over a test surface.');
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
218 %!
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
219 %! npts = 5;
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
220 %! tt = linspace(0.0,1.0,npts);
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
221 %! dsrf = nrbderiv(srf);
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
222 %!
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
223 %! [p1, dp] = nrbdeval(srf, dsrf, {tt, tt});
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
224 %!
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
225 %! up2 = vecnorm(dp{1});
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
226 %! vp2 = vecnorm(dp{2});
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
227 %!
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
228 %! hold on;
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
229 %! plot3(p1(1,:),p1(2,:),p1(3,:),'ro');
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
230 %! h1 = quiver3(p1(1,:),p1(2,:),p1(3,:),up2(1,:),up2(2,:),up2(3,:));
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
231 %! h2 = quiver3(p1(1,:),p1(2,:),p1(3,:),vp2(1,:),vp2(2,:),vp2(3,:));
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
232 %! set(h1,'Color','black');
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
233 %! set(h2,'Color','black');
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
234 %!
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
235 %! hold off;
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
236
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
237 %!test
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
238 %! knots{1} = [0 0 0 1 1 1];
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
239 %! knots{2} = [0 0 0 .5 1 1 1];
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
240 %! knots{3} = [0 0 0 0 1 1 1 1];
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
241 %! cx = [0 0.5 1]; nx = length(cx);
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
242 %! cy = [0 0.25 0.75 1]; ny = length(cy);
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
243 %! cz = [0 1/3 2/3 1]; nz = length(cz);
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
244 %! coefs(1,:,:,:) = repmat(reshape(cx,nx,1,1),[1 ny nz]);
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
245 %! coefs(2,:,:,:) = repmat(reshape(cy,1,ny,1),[nx 1 nz]);
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
246 %! coefs(3,:,:,:) = repmat(reshape(cz,1,1,nz),[nx ny 1]);
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
247 %! coefs(4,:,:,:) = 1;
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
248 %! nurbs = nrbmak(coefs, knots);
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
249 %! x = rand(5,1); y = rand(5,1); z = rand(5,1);
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
250 %! tt = [x y z]';
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
251 %! ders = nrbderiv(nurbs);
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
252 %! [points,jac] = nrbdeval(nurbs,ders,tt);
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
253 %! assert(points,tt,1e-10)
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
254 %! assert(jac{1}(1,:,:),ones(size(jac{1}(1,:,:))),1e-12)
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
255 %! assert(jac{2}(2,:,:),ones(size(jac{2}(2,:,:))),1e-12)
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
256 %! assert(jac{3}(3,:,:),ones(size(jac{3}(3,:,:))),1e-12)
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
257 %!
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
258 %!test
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
259 %! knots{1} = [0 0 0 1 1 1];
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
260 %! knots{2} = [0 0 0 0 1 1 1 1];
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
261 %! knots{3} = [0 0 0 1 1 1];
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
262 %! cx = [0 0 1]; nx = length(cx);
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
263 %! cy = [0 0 0 1]; ny = length(cy);
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
264 %! cz = [0 0.5 1]; nz = length(cz);
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
265 %! coefs(1,:,:,:) = repmat(reshape(cx,nx,1,1),[1 ny nz]);
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
266 %! coefs(2,:,:,:) = repmat(reshape(cy,1,ny,1),[nx 1 nz]);
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
267 %! coefs(3,:,:,:) = repmat(reshape(cz,1,1,nz),[nx ny 1]);
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
268 %! coefs(4,:,:,:) = 1;
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
269 %! coefs = coefs([2 1 3 4],:,:,:);
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
270 %! nurbs = nrbmak(coefs, knots);
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
271 %! x = rand(5,1); y = rand(5,1); z = rand(5,1);
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
272 %! tt = [x y z]';
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
273 %! dnurbs = nrbderiv(nurbs);
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
274 %! [points, jac] = nrbdeval(nurbs,dnurbs,tt);
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
275 %! assert(points,[y.^3 x.^2 z]',1e-10);
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
276 %! assert(jac{2}(1,:,:),3*y'.^2,1e-12)
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
277 %! assert(jac{1}(2,:,:),2*x',1e-12)
97806581afd6 New version compatible with Matlab
rafavzqz
parents: 5552
diff changeset
278 %! assert(jac{3}(3,:,:),ones(size(z')),1e-12)