Mercurial > repos > public > sbplib
annotate +grid/Curve.m @ 103:bc5db54f9efd feature/arclen-param
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
author | Martin Almquist <martin.almquist@it.uu.se> |
---|---|
date | Mon, 07 Dec 2015 17:24:28 +0100 |
parents | ecf77a50d4fe |
children | ffd9e68f63cc |
rev | line source |
---|---|
0 | 1 classdef Curve |
2 properties | |
3 g | |
4 gp | |
5 transformation | |
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).
Martin Almquist <martin.almquist@it.uu.se>
parents:
86
diff
changeset
|
6 |
0 | 7 end |
8 methods | |
9 %TODO: | |
10 % Errors or FD if there is no derivative function added. | |
86
3c39dd714fb6
In Curve: Added numerical FD differentiation if derivative is not supplied. Added arc length computation based on the derivative. Added arc length parameterization (but this function is very slow.). In +util: Added fzero_vec.m and integral_vec.m, which call fzero and integral but take vector arguments.
Martin Almquist <martin.almquist@it.uu.se>
parents:
0
diff
changeset
|
11 % -semi-done |
0 | 12 |
13 % Concatenation of curves | |
14 % Subsections of curves | |
98
b30f3d8845f4
Removed arclength property. Constructor compatible again. Translation and rotation are fast now, but ti is slow.
Martin Almquist <martin.almquist@it.uu.se>
parents:
87
diff
changeset
|
15 % Stretching of curve parameter - semi-done |
0 | 16 % Curve to cell array of linesegments |
17 | |
103
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
18 % The curve parameter t must be in [0,1]. |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
19 % Can supply derivative. |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
20 function obj = Curve(g,gp,transformation) |
0 | 21 default_arg('gp',[]); |
22 default_arg('transformation',[]); | |
23 p_test = g(0); | |
24 assert(all(size(p_test) == [2,1]), 'A curve parametrization must return a 2x1 vector.'); | |
86
3c39dd714fb6
In Curve: Added numerical FD differentiation if derivative is not supplied. Added arc length computation based on the derivative. Added arc length parameterization (but this function is very slow.). In +util: Added fzero_vec.m and integral_vec.m, which call fzero and integral but take vector arguments.
Martin Almquist <martin.almquist@it.uu.se>
parents:
0
diff
changeset
|
25 |
0 | 26 if ~isempty(transformation) |
27 transformation.base_g = g; | |
28 transformation.base_gp = gp; | |
29 [g,gp] = grid.Curve.transform_g(g,gp,transformation); | |
30 end | |
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).
Martin Almquist <martin.almquist@it.uu.se>
parents:
86
diff
changeset
|
31 |
0 | 32 obj.g = g; |
33 obj.gp = gp; | |
34 obj.transformation = transformation; | |
86
3c39dd714fb6
In Curve: Added numerical FD differentiation if derivative is not supplied. Added arc length computation based on the derivative. Added arc length parameterization (but this function is very slow.). In +util: Added fzero_vec.m and integral_vec.m, which call fzero and integral but take vector arguments.
Martin Almquist <martin.almquist@it.uu.se>
parents:
0
diff
changeset
|
35 |
0 | 36 end |
37 | |
38 function n = normal(obj,t) | |
39 deriv = obj.gp(t); | |
40 normalization = sqrt(sum(deriv.^2,1)); | |
41 n = [-deriv(2,:)./normalization; deriv(1,:)./normalization]; | |
42 end | |
43 | |
44 | |
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).
Martin Almquist <martin.almquist@it.uu.se>
parents:
86
diff
changeset
|
45 % Plots a curve g(t) for 0<t<1, using n points. Returns a handle h to the plotted curve. |
0 | 46 % h = plot_curve(g,n) |
98
b30f3d8845f4
Removed arclength property. Constructor compatible again. Translation and rotation are fast now, but ti is slow.
Martin Almquist <martin.almquist@it.uu.se>
parents:
87
diff
changeset
|
47 function h = plot(obj,n) |
0 | 48 default_arg('n',100); |
49 | |
50 t = linspace(0,1,n); | |
51 p = obj.g(t); | |
98
b30f3d8845f4
Removed arclength property. Constructor compatible again. Translation and rotation are fast now, but ti is slow.
Martin Almquist <martin.almquist@it.uu.se>
parents:
87
diff
changeset
|
52 h = line(p(1,:),p(2,:)); |
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).
Martin Almquist <martin.almquist@it.uu.se>
parents:
86
diff
changeset
|
53 end |
0 | 54 |
55 function h= plot_normals(obj,l,n,m) | |
56 default_arg('l',0.1); | |
57 default_arg('n',10); | |
58 default_arg('m',100); | |
59 t_n = linspace(0,1,n); | |
60 | |
61 normals = obj.normal(t_n)*l; | |
62 | |
63 n0 = obj.g(t_n); | |
64 n1 = n0 + normals; | |
65 | |
66 h = line([n0(1,:); n1(1,:)],[n0(2,:); n1(2,:)]); | |
67 set(h,'Color',Color.red); | |
68 obj.plot(m); | |
69 end | |
70 | |
71 function h= show(obj,name) | |
72 p = obj.g(1/2); | |
73 n = obj.normal(1/2); | |
74 p = p + n*0.1; | |
75 | |
76 % Add arrow | |
77 | |
78 h = text(p(1),p(2),name); | |
79 h.HorizontalAlignment = 'center'; | |
80 h.VerticalAlignment = 'middle'; | |
81 | |
82 obj.plot(); | |
83 end | |
84 % Shows curve with name and arrow for direction. | |
85 | |
103
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
86 % Length of arc from parameter t0 to t1 (which may be vectors). |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
87 % Computed using derivative. |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
88 function L = arcLength(obj,t0,t1) |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
89 assert(~isempty(obj.gp),'Curve has no derivative!'); |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
90 speed = @(t) sqrt(sum(obj.gp(t).^2,1)); |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
91 L = integral_vec(speed,t0,t1); |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
92 end |
86
3c39dd714fb6
In Curve: Added numerical FD differentiation if derivative is not supplied. Added arc length computation based on the derivative. Added arc length parameterization (but this function is very slow.). In +util: Added fzero_vec.m and integral_vec.m, which call fzero and integral but take vector arguments.
Martin Almquist <martin.almquist@it.uu.se>
parents:
0
diff
changeset
|
93 |
98
b30f3d8845f4
Removed arclength property. Constructor compatible again. Translation and rotation are fast now, but ti is slow.
Martin Almquist <martin.almquist@it.uu.se>
parents:
87
diff
changeset
|
94 % Arc length parameterization. |
103
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
95 function curve = arcLengthParametrization(obj,N) |
98
b30f3d8845f4
Removed arclength property. Constructor compatible again. Translation and rotation are fast now, but ti is slow.
Martin Almquist <martin.almquist@it.uu.se>
parents:
87
diff
changeset
|
96 default_arg('N',100); |
86
3c39dd714fb6
In Curve: Added numerical FD differentiation if derivative is not supplied. Added arc length computation based on the derivative. Added arc length parameterization (but this function is very slow.). In +util: Added fzero_vec.m and integral_vec.m, which call fzero and integral but take vector arguments.
Martin Almquist <martin.almquist@it.uu.se>
parents:
0
diff
changeset
|
97 |
98
b30f3d8845f4
Removed arclength property. Constructor compatible again. Translation and rotation are fast now, but ti is slow.
Martin Almquist <martin.almquist@it.uu.se>
parents:
87
diff
changeset
|
98 % Construct arcLength function using splines |
b30f3d8845f4
Removed arclength property. Constructor compatible again. Translation and rotation are fast now, but ti is slow.
Martin Almquist <martin.almquist@it.uu.se>
parents:
87
diff
changeset
|
99 tvec = linspace(0,1,N); |
103
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
100 arcVec = obj.arcLength(0,tvec); |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
101 arcLength = spline(tvec,arcVec); |
98
b30f3d8845f4
Removed arclength property. Constructor compatible again. Translation and rotation are fast now, but ti is slow.
Martin Almquist <martin.almquist@it.uu.se>
parents:
87
diff
changeset
|
102 |
99
ecf77a50d4fe
The arclength parameter function was slow because it called fzero. Now it is constructed once and for all with splines. Much better performance.
Martin Almquist <martin.almquist@it.uu.se>
parents:
98
diff
changeset
|
103 % Stretch the parameter, construct function with splines |
103
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
104 arcParVec = fzero_vec(@(s)arcLength(s) - tvec*arcLength(1),[0-10*eps,1+10*eps]); |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
105 arcPar = spline(tvec,arcParVec); |
98
b30f3d8845f4
Removed arclength property. Constructor compatible again. Translation and rotation are fast now, but ti is slow.
Martin Almquist <martin.almquist@it.uu.se>
parents:
87
diff
changeset
|
106 |
b30f3d8845f4
Removed arclength property. Constructor compatible again. Translation and rotation are fast now, but ti is slow.
Martin Almquist <martin.almquist@it.uu.se>
parents:
87
diff
changeset
|
107 % New function and derivative |
b30f3d8845f4
Removed arclength property. Constructor compatible again. Translation and rotation are fast now, but ti is slow.
Martin Almquist <martin.almquist@it.uu.se>
parents:
87
diff
changeset
|
108 g_new = @(t)obj.g(arcPar(t)); |
103
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
109 gp_new = @(t) normalize(obj.gp(arcPar(t))); |
98
b30f3d8845f4
Removed arclength property. Constructor compatible again. Translation and rotation are fast now, but ti is slow.
Martin Almquist <martin.almquist@it.uu.se>
parents:
87
diff
changeset
|
110 curve = grid.Curve(g_new,gp_new); |
b30f3d8845f4
Removed arclength property. Constructor compatible again. Translation and rotation are fast now, but ti is slow.
Martin Almquist <martin.almquist@it.uu.se>
parents:
87
diff
changeset
|
111 |
86
3c39dd714fb6
In Curve: Added numerical FD differentiation if derivative is not supplied. Added arc length computation based on the derivative. Added arc length parameterization (but this function is very slow.). In +util: Added fzero_vec.m and integral_vec.m, which call fzero and integral but take vector arguments.
Martin Almquist <martin.almquist@it.uu.se>
parents:
0
diff
changeset
|
112 end |
3c39dd714fb6
In Curve: Added numerical FD differentiation if derivative is not supplied. Added arc length computation based on the derivative. Added arc length parameterization (but this function is very slow.). In +util: Added fzero_vec.m and integral_vec.m, which call fzero and integral but take vector arguments.
Martin Almquist <martin.almquist@it.uu.se>
parents:
0
diff
changeset
|
113 |
0 | 114 % how to make it work for methods without returns |
115 function p = subsref(obj,S) | |
116 %Should i add error checking here? | |
117 %Maybe if you want performance you fetch obj.g and then use that | |
118 switch S(1).type | |
119 case '()' | |
120 p = obj.g(S.subs{1}); | |
121 % case '.' | |
122 | |
123 % p = obj.(S.subs); | |
124 otherwise | |
125 p = builtin('subsref',obj,S); | |
126 % error() | |
127 end | |
128 end | |
129 | |
130 | |
131 %% TRANSFORMATION OF A CURVE | |
132 function D = reverse(C) | |
133 % g = C.g; | |
134 % gp = C.gp; | |
135 % D = grid.Curve(@(t)g(1-t),@(t)-gp(1-t)); | |
136 D = C.transform([],[],-1); | |
137 end | |
138 | |
139 function D = transform(C,A,b,flip) | |
140 default_arg('A',[1 0; 0 1]); | |
141 default_arg('b',[0; 0]); | |
142 default_arg('flip',1); | |
143 if isempty(C.transformation) | |
144 g = C.g; | |
145 gp = C.gp; | |
146 transformation.A = A; | |
147 transformation.b = b; | |
148 transformation.flip = flip; | |
149 else | |
150 g = C.transformation.base_g; | |
151 gp = C.transformation.base_gp; | |
152 A_old = C.transformation.A; | |
153 b_old = C.transformation.b; | |
154 flip_old = C.transformation.flip; | |
155 | |
156 transformation.A = A*A_old; | |
157 transformation.b = A*b_old + b; | |
158 transformation.flip = flip*flip_old; | |
159 end | |
160 | |
161 D = grid.Curve(g,gp,transformation); | |
162 | |
163 end | |
164 | |
165 function D = translate(C,a) | |
166 g = C.g; | |
167 gp = C.gp; | |
168 | |
169 % function v = g_fun(t) | |
170 % x = g(t); | |
171 % v(1,:) = x(1,:)+a(1); | |
172 % v(2,:) = x(2,:)+a(2); | |
173 % end | |
174 | |
175 % D = grid.Curve(@g_fun,gp); | |
176 | |
177 D = C.transform([],a); | |
178 end | |
179 | |
180 function D = mirror(C, a, b) | |
181 assert_size(a,[2,1]); | |
182 assert_size(b,[2,1]); | |
183 | |
184 g = C.g; | |
185 gp = C.gp; | |
186 | |
187 l = b-a; | |
188 lx = l(1); | |
189 ly = l(2); | |
190 | |
191 | |
192 % fprintf('Singular?\n') | |
193 | |
194 A = [lx^2-ly^2 2*lx*ly; 2*lx*ly ly^2-lx^2]/(l'*l); | |
195 | |
196 % function v = g_fun(t) | |
197 % % v = a + A*(g(t)-a) | |
198 % x = g(t); | |
199 | |
200 % ax1 = x(1,:)-a(1); | |
201 % ax2 = x(2,:)-a(2); | |
202 % v(1,:) = a(1)+A(1,:)*[ax1;ax2]; | |
203 % v(2,:) = a(2)+A(2,:)*[ax1;ax2]; | |
204 % end | |
205 | |
206 % function v = gp_fun(t) | |
207 % v = A*gp(t); | |
208 % end | |
209 | |
210 % D = grid.Curve(@g_fun,@gp_fun); | |
211 | |
212 % g = A(g-a)+a = Ag - Aa + a; | |
213 b = - A*a + a; | |
214 D = C.transform(A,b); | |
215 | |
216 end | |
217 | |
218 function D = rotate(C,a,rad) | |
219 assert_size(a, [2,1]); | |
220 assert_size(rad, [1,1]); | |
221 g = C.g; | |
222 gp = C.gp; | |
223 | |
224 | |
225 A = [cos(rad) -sin(rad); sin(rad) cos(rad)]; | |
226 | |
227 % function v = g_fun(t) | |
228 % % v = a + A*(g(t)-a) | |
229 % x = g(t); | |
230 | |
231 % ax1 = x(1,:)-a(1); | |
232 % ax2 = x(2,:)-a(2); | |
233 % v(1,:) = a(1)+A(1,:)*[ax1;ax2]; | |
234 % v(2,:) = a(2)+A(2,:)*[ax1;ax2]; | |
235 % end | |
236 | |
237 % function v = gp_fun(t) | |
238 % v = A*gp(t); | |
239 % end | |
240 | |
241 % D = grid.Curve(@g_fun,@gp_fun); | |
242 | |
243 | |
244 % g = A(g-a)+a = Ag - Aa + a; | |
245 b = - A*a + a; | |
246 D = C.transform(A,b); | |
247 end | |
248 end | |
249 | |
250 methods (Static) | |
86
3c39dd714fb6
In Curve: Added numerical FD differentiation if derivative is not supplied. Added arc length computation based on the derivative. Added arc length parameterization (but this function is very slow.). In +util: Added fzero_vec.m and integral_vec.m, which call fzero and integral but take vector arguments.
Martin Almquist <martin.almquist@it.uu.se>
parents:
0
diff
changeset
|
251 |
3c39dd714fb6
In Curve: Added numerical FD differentiation if derivative is not supplied. Added arc length computation based on the derivative. Added arc length parameterization (but this function is very slow.). In +util: Added fzero_vec.m and integral_vec.m, which call fzero and integral but take vector arguments.
Martin Almquist <martin.almquist@it.uu.se>
parents:
0
diff
changeset
|
252 function gp_out = numerical_derivative(g,D1) |
3c39dd714fb6
In Curve: Added numerical FD differentiation if derivative is not supplied. Added arc length computation based on the derivative. Added arc length parameterization (but this function is very slow.). In +util: Added fzero_vec.m and integral_vec.m, which call fzero and integral but take vector arguments.
Martin Almquist <martin.almquist@it.uu.se>
parents:
0
diff
changeset
|
253 m = length(D1); L = 1; % Assume curve parameter from 0 to 1. |
3c39dd714fb6
In Curve: Added numerical FD differentiation if derivative is not supplied. Added arc length computation based on the derivative. Added arc length parameterization (but this function is very slow.). In +util: Added fzero_vec.m and integral_vec.m, which call fzero and integral but take vector arguments.
Martin Almquist <martin.almquist@it.uu.se>
parents:
0
diff
changeset
|
254 t = linspace(0,L,m); |
103
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
255 gVec = g(t)'; |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
256 gpVec = (D1*gVec)'; |
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).
Martin Almquist <martin.almquist@it.uu.se>
parents:
86
diff
changeset
|
257 |
103
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
258 gp1_fun = spline(t,gpVec(1,:)); |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
259 gp2_fun = spline(t,gpVec(2,:)); |
86
3c39dd714fb6
In Curve: Added numerical FD differentiation if derivative is not supplied. Added arc length computation based on the derivative. Added arc length parameterization (but this function is very slow.). In +util: Added fzero_vec.m and integral_vec.m, which call fzero and integral but take vector arguments.
Martin Almquist <martin.almquist@it.uu.se>
parents:
0
diff
changeset
|
260 gp_out = @(t) [gp1_fun(t);gp2_fun(t)]; |
3c39dd714fb6
In Curve: Added numerical FD differentiation if derivative is not supplied. Added arc length computation based on the derivative. Added arc length parameterization (but this function is very slow.). In +util: Added fzero_vec.m and integral_vec.m, which call fzero and integral but take vector arguments.
Martin Almquist <martin.almquist@it.uu.se>
parents:
0
diff
changeset
|
261 |
3c39dd714fb6
In Curve: Added numerical FD differentiation if derivative is not supplied. Added arc length computation based on the derivative. Added arc length parameterization (but this function is very slow.). In +util: Added fzero_vec.m and integral_vec.m, which call fzero and integral but take vector arguments.
Martin Almquist <martin.almquist@it.uu.se>
parents:
0
diff
changeset
|
262 end |
3c39dd714fb6
In Curve: Added numerical FD differentiation if derivative is not supplied. Added arc length computation based on the derivative. Added arc length parameterization (but this function is very slow.). In +util: Added fzero_vec.m and integral_vec.m, which call fzero and integral but take vector arguments.
Martin Almquist <martin.almquist@it.uu.se>
parents:
0
diff
changeset
|
263 |
0 | 264 function obj = line(p1, p2) |
265 | |
266 function v = g_fun(t) | |
267 v(1,:) = p1(1) + t.*(p2(1)-p1(1)); | |
268 v(2,:) = p1(2) + t.*(p2(2)-p1(2)); | |
269 end | |
270 g = @g_fun; | |
271 | |
272 obj = grid.Curve(g); | |
273 end | |
274 | |
275 function obj = circle(c,r,phi) | |
276 default_arg('phi',[0; 2*pi]) | |
277 default_arg('c',[0; 0]) | |
278 default_arg('r',1) | |
279 | |
280 function v = g_fun(t) | |
281 w = phi(1)+t*(phi(2)-phi(1)); | |
282 v(1,:) = c(1) + r*cos(w); | |
283 v(2,:) = c(2) + r*sin(w); | |
284 end | |
285 | |
286 function v = g_fun_deriv(t) | |
287 w = phi(1)+t*(phi(2)-phi(1)); | |
288 v(1,:) = -(phi(2)-phi(1))*r*sin(w); | |
289 v(2,:) = (phi(2)-phi(1))*r*cos(w); | |
290 end | |
291 | |
292 obj = grid.Curve(@g_fun,@g_fun_deriv); | |
293 end | |
294 | |
295 function obj = bezier(p0, p1, p2, p3) | |
296 function v = g_fun(t) | |
297 v(1,:) = (1-t).^3*p0(1) + 3*(1-t).^2.*t*p1(1) + 3*(1-t).*t.^2*p2(1) + t.^3*p3(1); | |
298 v(2,:) = (1-t).^3*p0(2) + 3*(1-t).^2.*t*p1(2) + 3*(1-t).*t.^2*p2(2) + t.^3*p3(2); | |
299 end | |
300 | |
301 function v = g_fun_deriv(t) | |
302 v(1,:) = 3*(1-t).^2*(p1(1)-p0(1)) + 6*(1-t).*t*(p2(1)-p1(1)) + 3*t.^2*(p3(1)-p2(1)); | |
303 v(2,:) = 3*(1-t).^2*(p1(2)-p0(2)) + 6*(1-t).*t*(p2(2)-p1(2)) + 3*t.^2*(p3(2)-p2(2)); | |
304 end | |
305 | |
306 obj = grid.Curve(@g_fun,@g_fun_deriv); | |
307 end | |
308 | |
309 | |
310 function [g_out,gp_out] = transform_g(g,gp,tr) | |
311 A = tr.A; | |
312 b = tr.b; | |
313 flip = tr.flip; | |
314 | |
315 function v = g_fun_noflip(t) | |
316 % v = A*g + b | |
317 x = g(t); | |
318 | |
319 v(1,:) = A(1,:)*x+b(1); | |
320 v(2,:) = A(2,:)*x+b(2); | |
321 end | |
322 | |
323 function v = g_fun_flip(t) | |
324 % v = A*g + b | |
325 x = g(1-t); | |
326 | |
327 v(1,:) = A(1,:)*x+b(1); | |
328 v(2,:) = A(2,:)*x+b(2); | |
329 end | |
330 | |
331 | |
332 switch flip | |
333 case 1 | |
334 g_out = @g_fun_noflip; | |
335 gp_out = @(t)A*gp(t); | |
336 case -1 | |
337 g_out = @g_fun_flip; | |
338 gp_out = @(t)-A*gp(1-t); | |
339 end | |
340 end | |
341 | |
86
3c39dd714fb6
In Curve: Added numerical FD differentiation if derivative is not supplied. Added arc length computation based on the derivative. Added arc length parameterization (but this function is very slow.). In +util: Added fzero_vec.m and integral_vec.m, which call fzero and integral but take vector arguments.
Martin Almquist <martin.almquist@it.uu.se>
parents:
0
diff
changeset
|
342 end |
0 | 343 end |
86
3c39dd714fb6
In Curve: Added numerical FD differentiation if derivative is not supplied. Added arc length computation based on the derivative. Added arc length parameterization (but this function is very slow.). In +util: Added fzero_vec.m and integral_vec.m, which call fzero and integral but take vector arguments.
Martin Almquist <martin.almquist@it.uu.se>
parents:
0
diff
changeset
|
344 |
3c39dd714fb6
In Curve: Added numerical FD differentiation if derivative is not supplied. Added arc length computation based on the derivative. Added arc length parameterization (but this function is very slow.). In +util: Added fzero_vec.m and integral_vec.m, which call fzero and integral but take vector arguments.
Martin Almquist <martin.almquist@it.uu.se>
parents:
0
diff
changeset
|
345 function g_norm = normalize(g0) |
103
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
346 g1 = g0(1,:); |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
347 g2 = g0(2,:); |
86
3c39dd714fb6
In Curve: Added numerical FD differentiation if derivative is not supplied. Added arc length computation based on the derivative. Added arc length parameterization (but this function is very slow.). In +util: Added fzero_vec.m and integral_vec.m, which call fzero and integral but take vector arguments.
Martin Almquist <martin.almquist@it.uu.se>
parents:
0
diff
changeset
|
348 normalization = sqrt(sum(g0.^2,1)); |
3c39dd714fb6
In Curve: Added numerical FD differentiation if derivative is not supplied. Added arc length computation based on the derivative. Added arc length parameterization (but this function is very slow.). In +util: Added fzero_vec.m and integral_vec.m, which call fzero and integral but take vector arguments.
Martin Almquist <martin.almquist@it.uu.se>
parents:
0
diff
changeset
|
349 g_norm = [g1./normalization; g2./normalization]; |
3c39dd714fb6
In Curve: Added numerical FD differentiation if derivative is not supplied. Added arc length computation based on the derivative. Added arc length parameterization (but this function is very slow.). In +util: Added fzero_vec.m and integral_vec.m, which call fzero and integral but take vector arguments.
Martin Almquist <martin.almquist@it.uu.se>
parents:
0
diff
changeset
|
350 end |
3c39dd714fb6
In Curve: Added numerical FD differentiation if derivative is not supplied. Added arc length computation based on the derivative. Added arc length parameterization (but this function is very slow.). In +util: Added fzero_vec.m and integral_vec.m, which call fzero and integral but take vector arguments.
Martin Almquist <martin.almquist@it.uu.se>
parents:
0
diff
changeset
|
351 |
103
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
352 function I = integral_vec(f,a,b) |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
353 % Wrapper around the built-in function integral that |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
354 % handles multiple limits. |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
355 |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
356 Na = length(a); |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
357 Nb = length(b); |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
358 assert(Na == 1 || Nb == 1 || Na==Nb,... |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
359 'a and b must have same length, unless one is a scalar.'); |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
360 |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
361 if(Na>Nb); |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
362 I = zeros(size(a)); |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
363 for i = 1:Na |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
364 I(i) = integral(f,a(i),b); |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
365 end |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
366 elseif(Nb>Na) |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
367 I = zeros(size(b)); |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
368 for i = 1:Nb |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
369 I(i) = integral(f,a,b(i)); |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
370 end |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
371 else |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
372 I = zeros(size(b)); |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
373 for i = 1:Nb |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
374 I(i) = integral(f,a(i),b(i)); |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
375 end |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
376 end |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
377 end |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
378 |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
379 function I = fzero_vec(f,lim) |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
380 % Wrapper around the built-in function fzero that |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
381 % handles multiple functions (vector-valued f). |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
382 |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
383 fval = f(lim(1)); |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
384 I = zeros(size(fval)); |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
385 |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
386 for i = 1:length(fval) |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
387 e = zeros(size(fval)); |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
388 e(i) = 1; |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
389 I(i) = fzero(@(t) sum(e.*f(t)),lim); |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
390 end |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
391 |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
392 end |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
393 |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
394 % Returns a function handle to the spline. |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
395 function f = spline(tval,fval,spline_order) |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
396 default_arg('spline_order',4); |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
397 [m,~] = size(tval); |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
398 assert(m==1,'Need row vectors.'); |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
399 |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
400 % make vectors longer to be safe slightly beyond edges. |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
401 dt0 = tval(2)-tval(1); dt1 = tval(end)-tval(end-1); |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
402 df0 = fval(2)-fval(1); df1 = fval(end)-fval(end-1); |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
403 tval = [tval(1)-dt0, tval, tval(end)+dt1]; |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
404 fval = [fval(1)-df0, fval, fval(end)+df1]; |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
405 |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
406 f_spline = spapi( optknt(tval,spline_order), tval, fval ); |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
407 f = @(t) fnval(f_spline,t); |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
408 end |
bc5db54f9efd
fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
Martin Almquist <martin.almquist@it.uu.se>
parents:
99
diff
changeset
|
409 |
86
3c39dd714fb6
In Curve: Added numerical FD differentiation if derivative is not supplied. Added arc length computation based on the derivative. Added arc length parameterization (but this function is very slow.). In +util: Added fzero_vec.m and integral_vec.m, which call fzero and integral but take vector arguments.
Martin Almquist <martin.almquist@it.uu.se>
parents:
0
diff
changeset
|
410 |
3c39dd714fb6
In Curve: Added numerical FD differentiation if derivative is not supplied. Added arc length computation based on the derivative. Added arc length parameterization (but this function is very slow.). In +util: Added fzero_vec.m and integral_vec.m, which call fzero and integral but take vector arguments.
Martin Almquist <martin.almquist@it.uu.se>
parents:
0
diff
changeset
|
411 |