comparison 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
comparison
equal deleted inserted replaced
86:3c39dd714fb6 87:0a29a60e0b21
1 m = 201; L = 1; order = 4;
2 close all;
3 tic
4
5 g1 = @(t) 2*pi*t.*sin(2*pi*t);
6 g2 = @(t) 2*pi*t.*cos(2*pi*t);
7 g = @(t) [g1(t);g2(t)];
8
9 t = linspace(0,L,m)'; dt = L/(m-1);
10 ops = sbp.Ordinary(m,dt,order);
11 D = ops.derivatives.D1;
12
13 C = grid.Curve(g,[],[],D);
14
15 % Function
16 figure;
17 C.plot([],'bo');
18 hold on
19 plot(g1(t),g2(t),'r-');
20 drawnow
21
22 % Derivative
23 figure
24 C.plot_derivative([],'bo');
25 hold on;
26 plot(2*pi*sin(2*pi*t) + (2*pi)^2*t.*cos(2*pi*t),...
27 2*pi*cos(2*pi*t) - (2*pi)^2*t.*sin(2*pi*t),'r-')
28 drawnow
29
30 % Arc length
31 L = C.arc_length_fun(t);
32 figure;
33 plot(t,L)
34 drawnow
35
36 % Stretch curve
37 C2 = C.stretch_parameter();
38 z = linspace(0,1,m);
39 gnew = C2.g(z);
40 gpnew = C2.gp(z);
41
42 % Compare stretched and unstretched curves.
43 figure
44 plot(g1(t),g2(t),'b*',gnew(1,:),gnew(2,:),'ro');
45
46 % Compare stretched and unstretched derivatives.
47 figure
48 theta = linspace(0,2*pi,100);
49 plot(cos(theta),sin(theta),'-b',gpnew(1,:),gpnew(2,:),'rx');
50
51 toc
52
53
54
55