changeset 1097:eec03e78c6f2 feature/dataspline

Merge in default
author Jonatan Werpers <jonatan@werpers.com>
date Mon, 08 Apr 2019 22:30:47 +0200
parents ad3089f04e0b (diff) 78d7e4e28e3e (current diff)
children 36d092a00040
files
diffstat 2 files changed, 28 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/+parametrization/Curve.m	Mon Apr 08 20:15:37 2019 +0000
+++ b/+parametrization/Curve.m	Mon Apr 08 22:30:47 2019 +0200
@@ -349,8 +349,6 @@
     end
 end
 
-
-
 function g_norm = normalize(g0)
     g1 = g0(1,:);
     g2 = g0(2,:);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/+parametrization/dataSpline.m	Mon Apr 08 22:30:47 2019 +0200
@@ -0,0 +1,28 @@
+% 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);
+
+	pp_g = spapi(4, t_data, f_data);
+	pp_gp = fnder(pp_g);
+
+	% Reparametrize with parameter s from 0 to 1 to use Curve class
+    tmin = min(t_data);
+    tmax = max(t_data);
+    t = @(s) tmin + s*(tmax-tmin);
+    dt_ds = @(s) 0*s + (tmax-tmin);
+	g = @(s) [t(s); fnval(pp_g, t(s))];
+	gp = @(s) [dt_ds(s); fnval(pp_gp, t(s)).*dt_ds(s)];
+
+	% Create Curve object and reparametrize with arclength parametrization
+	C = parametrization.Curve(g, gp);
+	C = C.arcLengthParametrization(m_data);
+end