comparison +parametrization/dataSpline.m @ 1089:d7f6c10eab13 feature/dataspline

Add function parametrization/dataSpline which accepts data points and returns a Curve object consisting of a spline interpolant with the arclength parametrization.
author Martin Almquist <malmquist@stanford.edu>
date Thu, 04 Apr 2019 17:57:24 -0700
parents
children b4054942e277
comparison
equal deleted inserted replaced
1088:acf19ecd1338 1089:d7f6c10eab13
1 % Accepts data points (t_i, f_i) and returns a Curve object,
2 % using spline interpolation.
3 % The spline curve is parametrized with the arc length parametrization
4 % to facilitate better grids.
5 %
6 % t_data - vector
7 % f_data - vector
8 % C - curve object
9 function C = dataSpline(t_data, f_data)
10
11 assert(length(t_data)==length(f_data),'Vectors must be same length');
12 m_data = length(t_data);
13
14 % Create spline interpolant
15 f = parametrization.Curve.spline(t_data, f_data);
16
17 % Reparametrize with a parameter s in [0, 1]
18 tmin = min(t_data);
19 tmax = max(t_data);
20 t = @(s) tmin + s*(tmax-tmin);
21
22 % Create parameterized curve
23 g = @(s) [t(s); f(t(s))];
24
25 % Compute numerical derivative of curve using twice as many points as in data set
26 m = 2*m_data;
27 ops = sbp.D2Standard(m, {0, 1}, 6);
28 gp = parametrization.Curve.numericalDerivative(g, ops.D1);
29
30 % Create curve object
31 C = parametrization.Curve(g, gp);
32
33 % Reparametrize with arclength parametrization
34 C = C.arcLengthParametrization(m_data);
35
36 % To avoid nested function calls, evaluate curve and compute final spline.
37 tv = linspace(0, 1, m_data);
38 gv = C.g(tv);
39 g = parametrization.Curve.spline(tv, gv);
40 C = parametrization.Curve(g);
41
42 end