diff testArcLength.m @ 87:0a29a60e0b21

In Curve: Rearranged for speed. arc_length_fun is now a property of Curve. If it is not supplied, it is computed via the derivative and spline fitting. Switching to the arc length parameterization is much faster now. The new stuff can be tested with testArcLength.m (which should be deleted after that).
author Martin Almquist <martin.almquist@it.uu.se>
date Sun, 29 Nov 2015 22:23:09 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/testArcLength.m	Sun Nov 29 22:23:09 2015 +0100
@@ -0,0 +1,55 @@
+m = 201; L = 1; order = 4;
+close all;
+tic
+
+g1 = @(t) 2*pi*t.*sin(2*pi*t);
+g2 = @(t) 2*pi*t.*cos(2*pi*t);
+g = @(t) [g1(t);g2(t)];
+
+t = linspace(0,L,m)'; dt = L/(m-1);
+ops = sbp.Ordinary(m,dt,order);
+D = ops.derivatives.D1;
+
+C = grid.Curve(g,[],[],D);
+
+% Function
+figure;
+C.plot([],'bo');
+hold on
+plot(g1(t),g2(t),'r-');
+drawnow
+
+% Derivative
+figure
+C.plot_derivative([],'bo');
+hold on;
+plot(2*pi*sin(2*pi*t) + (2*pi)^2*t.*cos(2*pi*t),...
+    2*pi*cos(2*pi*t) - (2*pi)^2*t.*sin(2*pi*t),'r-')
+drawnow
+
+% Arc length
+L = C.arc_length_fun(t);
+figure;
+plot(t,L)
+drawnow
+
+% Stretch curve
+C2 = C.stretch_parameter();
+z = linspace(0,1,m);
+gnew = C2.g(z);
+gpnew = C2.gp(z);
+
+% Compare stretched and unstretched curves.
+figure
+plot(g1(t),g2(t),'b*',gnew(1,:),gnew(2,:),'ro');
+
+% Compare stretched and unstretched derivatives. 
+figure
+theta = linspace(0,2*pi,100);
+plot(cos(theta),sin(theta),'-b',gpnew(1,:),gpnew(2,:),'rx');
+
+toc
+
+
+
+