annotate +parametrization/dataSpline.m @ 1092:47a72344db71 feature/dataspline

Bugfix in dataSpline(), reparameterize with parameter from 0 to 1 before using Curve.
author Martin Almquist <malmquist@stanford.edu>
date Fri, 05 Apr 2019 13:14:29 -0700
parents b4054942e277
children fdff002ebb32
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
1091
b4054942e277 Rewrite dataSpline() avoiding the spline function in Curve and using fnder for the differentiation
Jonatan Werpers <jonatan@werpers.com>
parents: 1089
diff changeset
14 pp_g = spapi(4, t_data, f_data); % equivalent to g = spapi(aptknt(t_data, 4), t_data, f_data)
b4054942e277 Rewrite dataSpline() avoiding the spline function in Curve and using fnder for the differentiation
Jonatan Werpers <jonatan@werpers.com>
parents: 1089
diff changeset
15 % or (not sure what the difference is?!)
1092
47a72344db71 Bugfix in dataSpline(), reparameterize with parameter from 0 to 1 before using Curve.
Martin Almquist <malmquist@stanford.edu>
parents: 1091
diff changeset
16 % pp_g = spapi(optknt(t_data, 4), t_data, f_data)
47a72344db71 Bugfix in dataSpline(), reparameterize with parameter from 0 to 1 before using Curve.
Martin Almquist <malmquist@stanford.edu>
parents: 1091
diff changeset
17 pp_gp = fnder(pp_g);
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
18
1092
47a72344db71 Bugfix in dataSpline(), reparameterize with parameter from 0 to 1 before using Curve.
Martin Almquist <malmquist@stanford.edu>
parents: 1091
diff changeset
19 % Reparametrize with parameter s from 0 to 1 to use Curve class
47a72344db71 Bugfix in dataSpline(), reparameterize with parameter from 0 to 1 before using Curve.
Martin Almquist <malmquist@stanford.edu>
parents: 1091
diff changeset
20 tmin = min(t_data);
47a72344db71 Bugfix in dataSpline(), reparameterize with parameter from 0 to 1 before using Curve.
Martin Almquist <malmquist@stanford.edu>
parents: 1091
diff changeset
21 tmax = max(t_data);
47a72344db71 Bugfix in dataSpline(), reparameterize with parameter from 0 to 1 before using Curve.
Martin Almquist <malmquist@stanford.edu>
parents: 1091
diff changeset
22 t = @(s) tmin + s*(tmax-tmin);
47a72344db71 Bugfix in dataSpline(), reparameterize with parameter from 0 to 1 before using Curve.
Martin Almquist <malmquist@stanford.edu>
parents: 1091
diff changeset
23 dt_ds = @(s) 0*s + (tmax-tmin);
47a72344db71 Bugfix in dataSpline(), reparameterize with parameter from 0 to 1 before using Curve.
Martin Almquist <malmquist@stanford.edu>
parents: 1091
diff changeset
24 g = @(s) [t(s); fnval(pp_g, t(s))];
47a72344db71 Bugfix in dataSpline(), reparameterize with parameter from 0 to 1 before using Curve.
Martin Almquist <malmquist@stanford.edu>
parents: 1091
diff changeset
25 gp = @(s) [dt_ds(s); fnval(pp_gp, t(s)).*dt_ds(s)];
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
26
1092
47a72344db71 Bugfix in dataSpline(), reparameterize with parameter from 0 to 1 before using Curve.
Martin Almquist <malmquist@stanford.edu>
parents: 1091
diff changeset
27 % Create Curve object and reparametrize with arclength parametrization
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
28 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
29 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
30 end