Mercurial > repos > public > sbplib
comparison +parametrization/Curve.m @ 1094:ad3089f04e0b feature/dataspline
Revert changes in Curve so that spline() is not a static method.
author | Martin Almquist <malmquist@stanford.edu> |
---|---|
date | Fri, 05 Apr 2019 13:33:25 -0700 |
parents | 3c187e639dfa |
children | 36d092a00040 |
comparison
equal
deleted
inserted
replaced
1093:fdff002ebb32 | 1094:ad3089f04e0b |
---|---|
101 assert(~isempty(obj.gp),'Curve has no derivative!'); | 101 assert(~isempty(obj.gp),'Curve has no derivative!'); |
102 | 102 |
103 % Construct arcLength function using splines | 103 % Construct arcLength function using splines |
104 tvec = linspace(0,1,N); | 104 tvec = linspace(0,1,N); |
105 arcVec = obj.arcLength(0,tvec); | 105 arcVec = obj.arcLength(0,tvec); |
106 tFunc = parametrization.Curve.spline(arcVec,tvec); % t as a function of arcLength | 106 tFunc = spline(arcVec,tvec); % t as a function of arcLength |
107 L = obj.arcLength(0,1); | 107 L = obj.arcLength(0,1); |
108 arcPar = @(s) tFunc(s*L); | 108 arcPar = @(s) tFunc(s*L); |
109 | 109 |
110 % New function and derivative | 110 % New function and derivative |
111 g_new = @(t)obj.g(arcPar(t)); | 111 g_new = @(t)obj.g(arcPar(t)); |
257 m = length(D1); | 257 m = length(D1); |
258 t = linspace(0,1,m); | 258 t = linspace(0,1,m); |
259 gVec = g(t)'; | 259 gVec = g(t)'; |
260 gpVec = (D1*gVec)'; | 260 gpVec = (D1*gVec)'; |
261 | 261 |
262 gp1_fun = parametrization.Curve.spline(t,gpVec(1,:)); | 262 gp1_fun = spline(t,gpVec(1,:)); |
263 gp2_fun = parametrization.Curve.spline(t,gpVec(2,:)); | 263 gp2_fun = spline(t,gpVec(2,:)); |
264 gp_out = @(t) [gp1_fun(t);gp2_fun(t)]; | 264 gp_out = @(t) [gp1_fun(t);gp2_fun(t)]; |
265 end | 265 end |
266 | 266 |
267 function obj = line(p1, p2) | 267 function obj = line(p1, p2) |
268 | 268 |
275 v(1,:) = t.*0 + (p2(1)-p1(1)); | 275 v(1,:) = t.*0 + (p2(1)-p1(1)); |
276 v(2,:) = t.*0 + (p2(2)-p1(2)); | 276 v(2,:) = t.*0 + (p2(2)-p1(2)); |
277 end | 277 end |
278 | 278 |
279 obj = parametrization.Curve(@g_fun, @g_fun_deriv); | 279 obj = parametrization.Curve(@g_fun, @g_fun_deriv); |
280 end | |
281 | |
282 % Returns a function handle to the spline. | |
283 function f = spline(tval,fval,spline_order) | |
284 default_arg('spline_order',4); | |
285 [m,~] = size(tval); | |
286 assert(m==1,'Need row vectors.'); | |
287 | |
288 f_spline = spapi( optknt(tval,spline_order), tval, fval ); | |
289 f = @(t) fnval(f_spline,t); | |
290 end | 280 end |
291 | 281 |
292 function obj = circle(c,r,phi) | 282 function obj = circle(c,r,phi) |
293 default_arg('phi',[0; 2*pi]) | 283 default_arg('phi',[0; 2*pi]) |
294 default_arg('c',[0; 0]) | 284 default_arg('c',[0; 0]) |
390 for i = 1:Nb | 380 for i = 1:Nb |
391 I(i) = integral(f,a(i),b(i)); | 381 I(i) = integral(f,a(i),b(i)); |
392 end | 382 end |
393 end | 383 end |
394 end | 384 end |
385 | |
386 % Returns a function handle to the spline. | |
387 function f = spline(tval,fval,spline_order) | |
388 default_arg('spline_order',4); | |
389 [m,~] = size(tval); | |
390 assert(m==1,'Need row vectors.'); | |
391 | |
392 f_spline = spapi( optknt(tval,spline_order), tval, fval ); | |
393 f = @(t) fnval(f_spline,t); | |
394 end |