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