Mercurial > repos > public > sbplib
changeset 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 | acf19ecd1338 |
children | 3c187e639dfa |
files | +parametrization/dataSpline.m |
diffstat | 1 files changed, 42 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
diff -r acf19ecd1338 -r d7f6c10eab13 +parametrization/dataSpline.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/+parametrization/dataSpline.m Thu Apr 04 17:57:24 2019 -0700 @@ -0,0 +1,42 @@ +% Accepts data points (t_i, f_i) and returns a Curve object, +% using spline interpolation. +% The spline curve is parametrized with the arc length parametrization +% to facilitate better grids. +% +% t_data - vector +% f_data - vector +% C - curve object +function C = dataSpline(t_data, f_data) + + assert(length(t_data)==length(f_data),'Vectors must be same length'); + m_data = length(t_data); + + % Create spline interpolant + f = parametrization.Curve.spline(t_data, f_data); + + % Reparametrize with a parameter s in [0, 1] + tmin = min(t_data); + tmax = max(t_data); + t = @(s) tmin + s*(tmax-tmin); + + % Create parameterized curve + g = @(s) [t(s); f(t(s))]; + + % Compute numerical derivative of curve using twice as many points as in data set + m = 2*m_data; + ops = sbp.D2Standard(m, {0, 1}, 6); + gp = parametrization.Curve.numericalDerivative(g, ops.D1); + + % Create curve object + C = parametrization.Curve(g, gp); + + % Reparametrize with arclength parametrization + C = C.arcLengthParametrization(m_data); + + % To avoid nested function calls, evaluate curve and compute final spline. + tv = linspace(0, 1, m_data); + gv = C.g(tv); + g = parametrization.Curve.spline(tv, gv); + C = parametrization.Curve(g); + +end