comparison +grid/Curve.m @ 99:ecf77a50d4fe feature/arclen-param

The arclength parameter function was slow because it called fzero. Now it is constructed once and for all with splines. Much better performance.
author Martin Almquist <martin.almquist@it.uu.se>
date Sun, 06 Dec 2015 15:41:42 +0100
parents b30f3d8845f4
children bc5db54f9efd
comparison
equal deleted inserted replaced
98:b30f3d8845f4 99:ecf77a50d4fe
106 % Construct arcLength function using splines 106 % Construct arcLength function using splines
107 tvec = linspace(0,1,N); 107 tvec = linspace(0,1,N);
108 arcVec = grid.Curve.arcLength(obj.gp,0,tvec); 108 arcVec = grid.Curve.arcLength(obj.gp,0,tvec);
109 arcLength = grid.Curve.spline(tvec,arcVec); 109 arcLength = grid.Curve.spline(tvec,arcVec);
110 110
111 % Stretch the parameter 111 % Stretch the parameter, construct function with splines
112 arcPar = @(t) util.fzero_vec(@(s)arcLength(s) - t*arcLength(1),[0-10*eps,1+10*eps]); 112 arcParVec = util.fzero_vec(@(s)arcLength(s) - tvec*arcLength(1),[0-10*eps,1+10*eps]);
113 arcPar = grid.Curve.spline(tvec,arcParVec);
113 114
114 % New function and derivative 115 % New function and derivative
115 g_new = @(t)obj.g(arcPar(t)); 116 g_new = @(t)obj.g(arcPar(t));
116 gp_old = obj.gp; 117 gp_old = obj.gp;
117 gp_new = @(t) normalize(gp_old(arcPar(t))); 118 gp_new = @(t) normalize(gp_old(arcPar(t)));