Mercurial > repos > public > sbplib
annotate +parametrization/Curve.m @ 248:81e0ead29431 feature/beams
Fixed package names in +parametrization
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Mon, 05 Sep 2016 16:34:22 +0200 |
parents | 3a3cf386bb7e |
children | 0fd4b259af9e |
rev | line source |
---|---|
0 | 1 classdef Curve |
2 properties | |
3 g | |
4 gp | |
5 transformation | |
6 end | |
107
06c3034966b7
Added and changed some comments. Also my text editor removed a bunch of whitespace.
Jonatan Werpers <jonatan@werpers.com>
parents:
105
diff
changeset
|
7 |
0 | 8 methods |
9 %TODO: | |
10 % Concatenation of curves | |
11 % Subsections of curves | |
105
1df4f3704b76
Added error checking for all methods that use the derivative gp. Removed that from the to do list. Updated some comments.
Martin Almquist <martin.almquist@it.uu.se>
parents:
104
diff
changeset
|
12 % Stretching of curve parameter - done for arc length. |
0 | 13 % Curve to cell array of linesegments |
14 | |
107
06c3034966b7
Added and changed some comments. Also my text editor removed a bunch of whitespace.
Jonatan Werpers <jonatan@werpers.com>
parents:
105
diff
changeset
|
15 % Returns a curve object. |
06c3034966b7
Added and changed some comments. Also my text editor removed a bunch of whitespace.
Jonatan Werpers <jonatan@werpers.com>
parents:
105
diff
changeset
|
16 % g -- curve parametrization for parameter between 0 and 1 |
06c3034966b7
Added and changed some comments. Also my text editor removed a bunch of whitespace.
Jonatan Werpers <jonatan@werpers.com>
parents:
105
diff
changeset
|
17 % gp -- parametrization of curve derivative |
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 function obj = Curve(g,gp,transformation) |
0 | 19 default_arg('gp',[]); |
20 default_arg('transformation',[]); | |
21 p_test = g(0); | |
22 assert(all(size(p_test) == [2,1]), 'A curve parametrization must return a 2x1 vector.'); | |
107
06c3034966b7
Added and changed some comments. Also my text editor removed a bunch of whitespace.
Jonatan Werpers <jonatan@werpers.com>
parents:
105
diff
changeset
|
23 |
0 | 24 if ~isempty(transformation) |
25 transformation.base_g = g; | |
26 transformation.base_gp = gp; | |
248
81e0ead29431
Fixed package names in +parametrization
Jonatan Werpers <jonatan@werpers.com>
parents:
151
diff
changeset
|
27 [g,gp] = parametrization.Curve.transform_g(g,gp,transformation); |
0 | 28 end |
107
06c3034966b7
Added and changed some comments. Also my text editor removed a bunch of whitespace.
Jonatan Werpers <jonatan@werpers.com>
parents:
105
diff
changeset
|
29 |
0 | 30 obj.g = g; |
31 obj.gp = gp; | |
32 obj.transformation = transformation; | |
107
06c3034966b7
Added and changed some comments. Also my text editor removed a bunch of whitespace.
Jonatan Werpers <jonatan@werpers.com>
parents:
105
diff
changeset
|
33 |
0 | 34 end |
35 | |
36 function n = normal(obj,t) | |
105
1df4f3704b76
Added error checking for all methods that use the derivative gp. Removed that from the to do list. Updated some comments.
Martin Almquist <martin.almquist@it.uu.se>
parents:
104
diff
changeset
|
37 assert(~isempty(obj.gp),'Curve has no derivative!'); |
0 | 38 deriv = obj.gp(t); |
39 normalization = sqrt(sum(deriv.^2,1)); | |
40 n = [-deriv(2,:)./normalization; deriv(1,:)./normalization]; | |
41 end | |
42 | |
43 | |
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
|
44 % Plots a curve g(t) for 0<t<1, using n points. Returns a handle h to the plotted curve. |
0 | 45 % 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
|
46 function h = plot(obj,n) |
0 | 47 default_arg('n',100); |
48 | |
49 t = linspace(0,1,n); | |
50 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
|
51 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
|
52 end |
0 | 53 |
54 function h= plot_normals(obj,l,n,m) | |
55 default_arg('l',0.1); | |
56 default_arg('n',10); | |
57 default_arg('m',100); | |
58 t_n = linspace(0,1,n); | |
59 | |
60 normals = obj.normal(t_n)*l; | |
61 | |
62 n0 = obj.g(t_n); | |
63 n1 = n0 + normals; | |
64 | |
65 h = line([n0(1,:); n1(1,:)],[n0(2,:); n1(2,:)]); | |
66 set(h,'Color',Color.red); | |
67 obj.plot(m); | |
68 end | |
69 | |
70 function h= show(obj,name) | |
71 p = obj.g(1/2); | |
72 n = obj.normal(1/2); | |
73 p = p + n*0.1; | |
74 | |
75 % Add arrow | |
76 | |
77 h = text(p(1),p(2),name); | |
78 h.HorizontalAlignment = 'center'; | |
79 h.VerticalAlignment = 'middle'; | |
80 | |
81 obj.plot(); | |
82 end | |
83 % Shows curve with name and arrow for direction. | |
84 | |
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
|
85 % 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
|
86 % 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
|
87 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
|
88 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
|
89 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
|
90 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
|
91 end |
107
06c3034966b7
Added and changed some comments. Also my text editor removed a bunch of whitespace.
Jonatan Werpers <jonatan@werpers.com>
parents:
105
diff
changeset
|
92 |
06c3034966b7
Added and changed some comments. Also my text editor removed a bunch of whitespace.
Jonatan Werpers <jonatan@werpers.com>
parents:
105
diff
changeset
|
93 % Creates the arc length parameterization of a curve. |
06c3034966b7
Added and changed some comments. Also my text editor removed a bunch of whitespace.
Jonatan Werpers <jonatan@werpers.com>
parents:
105
diff
changeset
|
94 % N -- number of points used to approximate the arclength function |
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); |
105
1df4f3704b76
Added error checking for all methods that use the derivative gp. Removed that from the to do list. Updated some comments.
Martin Almquist <martin.almquist@it.uu.se>
parents:
104
diff
changeset
|
97 assert(~isempty(obj.gp),'Curve has no derivative!'); |
107
06c3034966b7
Added and changed some comments. Also my text editor removed a bunch of whitespace.
Jonatan Werpers <jonatan@werpers.com>
parents:
105
diff
changeset
|
98 |
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
|
99 % 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
|
100 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
|
101 arcVec = obj.arcLength(0,tvec); |
104
ffd9e68f63cc
Splined in the other direction! Works great. Runs faster. Removed ugly fix outside [0,1] in spline(). Camelcased numerical_derivative().
Martin Almquist <martin.almquist@it.uu.se>
parents:
103
diff
changeset
|
102 tFunc = spline(arcVec,tvec); % t as a function of arcLength |
ffd9e68f63cc
Splined in the other direction! Works great. Runs faster. Removed ugly fix outside [0,1] in spline(). Camelcased numerical_derivative().
Martin Almquist <martin.almquist@it.uu.se>
parents:
103
diff
changeset
|
103 L = obj.arcLength(0,1); |
ffd9e68f63cc
Splined in the other direction! Works great. Runs faster. Removed ugly fix outside [0,1] in spline(). Camelcased numerical_derivative().
Martin Almquist <martin.almquist@it.uu.se>
parents:
103
diff
changeset
|
104 arcPar = @(s) tFunc(s*L); |
107
06c3034966b7
Added and changed some comments. Also my text editor removed a bunch of whitespace.
Jonatan Werpers <jonatan@werpers.com>
parents:
105
diff
changeset
|
105 |
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 % 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
|
107 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
|
108 gp_new = @(t) normalize(obj.gp(arcPar(t))); |
248
81e0ead29431
Fixed package names in +parametrization
Jonatan Werpers <jonatan@werpers.com>
parents:
151
diff
changeset
|
109 curve = parametrization.Curve(g_new,gp_new); |
107
06c3034966b7
Added and changed some comments. Also my text editor removed a bunch of whitespace.
Jonatan Werpers <jonatan@werpers.com>
parents:
105
diff
changeset
|
110 |
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
|
111 end |
107
06c3034966b7
Added and changed some comments. Also my text editor removed a bunch of whitespace.
Jonatan Werpers <jonatan@werpers.com>
parents:
105
diff
changeset
|
112 |
0 | 113 % how to make it work for methods without returns |
114 function p = subsref(obj,S) | |
115 %Should i add error checking here? | |
116 %Maybe if you want performance you fetch obj.g and then use that | |
117 switch S(1).type | |
118 case '()' | |
119 p = obj.g(S.subs{1}); | |
120 % case '.' | |
121 | |
122 % p = obj.(S.subs); | |
123 otherwise | |
124 p = builtin('subsref',obj,S); | |
125 % error() | |
126 end | |
127 end | |
128 | |
129 | |
130 %% TRANSFORMATION OF A CURVE | |
131 function D = reverse(C) | |
132 % g = C.g; | |
133 % gp = C.gp; | |
248
81e0ead29431
Fixed package names in +parametrization
Jonatan Werpers <jonatan@werpers.com>
parents:
151
diff
changeset
|
134 % D = parametrization.Curve(@(t)g(1-t),@(t)-gp(1-t)); |
0 | 135 D = C.transform([],[],-1); |
136 end | |
137 | |
138 function D = transform(C,A,b,flip) | |
139 default_arg('A',[1 0; 0 1]); | |
140 default_arg('b',[0; 0]); | |
141 default_arg('flip',1); | |
142 if isempty(C.transformation) | |
143 g = C.g; | |
144 gp = C.gp; | |
145 transformation.A = A; | |
146 transformation.b = b; | |
147 transformation.flip = flip; | |
148 else | |
149 g = C.transformation.base_g; | |
150 gp = C.transformation.base_gp; | |
151 A_old = C.transformation.A; | |
152 b_old = C.transformation.b; | |
153 flip_old = C.transformation.flip; | |
154 | |
155 transformation.A = A*A_old; | |
156 transformation.b = A*b_old + b; | |
157 transformation.flip = flip*flip_old; | |
158 end | |
159 | |
248
81e0ead29431
Fixed package names in +parametrization
Jonatan Werpers <jonatan@werpers.com>
parents:
151
diff
changeset
|
160 D = parametrization.Curve(g,gp,transformation); |
0 | 161 |
162 end | |
163 | |
164 function D = translate(C,a) | |
165 g = C.g; | |
166 gp = C.gp; | |
167 | |
168 % function v = g_fun(t) | |
169 % x = g(t); | |
170 % v(1,:) = x(1,:)+a(1); | |
171 % v(2,:) = x(2,:)+a(2); | |
172 % end | |
173 | |
248
81e0ead29431
Fixed package names in +parametrization
Jonatan Werpers <jonatan@werpers.com>
parents:
151
diff
changeset
|
174 % D = parametrization.Curve(@g_fun,gp); |
0 | 175 |
176 D = C.transform([],a); | |
177 end | |
178 | |
179 function D = mirror(C, a, b) | |
180 assert_size(a,[2,1]); | |
181 assert_size(b,[2,1]); | |
182 | |
183 g = C.g; | |
184 gp = C.gp; | |
185 | |
186 l = b-a; | |
187 lx = l(1); | |
188 ly = l(2); | |
189 | |
190 | |
191 % fprintf('Singular?\n') | |
192 | |
193 A = [lx^2-ly^2 2*lx*ly; 2*lx*ly ly^2-lx^2]/(l'*l); | |
194 | |
195 % function v = g_fun(t) | |
196 % % v = a + A*(g(t)-a) | |
197 % x = g(t); | |
198 | |
199 % ax1 = x(1,:)-a(1); | |
200 % ax2 = x(2,:)-a(2); | |
201 % v(1,:) = a(1)+A(1,:)*[ax1;ax2]; | |
202 % v(2,:) = a(2)+A(2,:)*[ax1;ax2]; | |
203 % end | |
204 | |
205 % function v = gp_fun(t) | |
206 % v = A*gp(t); | |
207 % end | |
208 | |
248
81e0ead29431
Fixed package names in +parametrization
Jonatan Werpers <jonatan@werpers.com>
parents:
151
diff
changeset
|
209 % D = parametrization.Curve(@g_fun,@gp_fun); |
0 | 210 |
211 % g = A(g-a)+a = Ag - Aa + a; | |
212 b = - A*a + a; | |
213 D = C.transform(A,b); | |
214 | |
215 end | |
216 | |
217 function D = rotate(C,a,rad) | |
218 assert_size(a, [2,1]); | |
219 assert_size(rad, [1,1]); | |
220 g = C.g; | |
221 gp = C.gp; | |
222 | |
223 | |
224 A = [cos(rad) -sin(rad); sin(rad) cos(rad)]; | |
225 | |
226 % function v = g_fun(t) | |
227 % % v = a + A*(g(t)-a) | |
228 % x = g(t); | |
229 | |
230 % ax1 = x(1,:)-a(1); | |
231 % ax2 = x(2,:)-a(2); | |
232 % v(1,:) = a(1)+A(1,:)*[ax1;ax2]; | |
233 % v(2,:) = a(2)+A(2,:)*[ax1;ax2]; | |
234 % end | |
235 | |
236 % function v = gp_fun(t) | |
237 % v = A*gp(t); | |
238 % end | |
239 | |
248
81e0ead29431
Fixed package names in +parametrization
Jonatan Werpers <jonatan@werpers.com>
parents:
151
diff
changeset
|
240 % D = parametrization.Curve(@g_fun,@gp_fun); |
0 | 241 |
242 | |
243 % g = A(g-a)+a = Ag - Aa + a; | |
244 b = - A*a + a; | |
245 D = C.transform(A,b); | |
246 end | |
247 end | |
248 | |
249 methods (Static) | |
107
06c3034966b7
Added and changed some comments. Also my text editor removed a bunch of whitespace.
Jonatan Werpers <jonatan@werpers.com>
parents:
105
diff
changeset
|
250 |
06c3034966b7
Added and changed some comments. Also my text editor removed a bunch of whitespace.
Jonatan Werpers <jonatan@werpers.com>
parents:
105
diff
changeset
|
251 % Computes the derivative of g: R -> R^2 using an operator D1 |
104
ffd9e68f63cc
Splined in the other direction! Works great. Runs faster. Removed ugly fix outside [0,1] in spline(). Camelcased numerical_derivative().
Martin Almquist <martin.almquist@it.uu.se>
parents:
103
diff
changeset
|
252 function gp_out = numericalDerivative(g,D1) |
107
06c3034966b7
Added and changed some comments. Also my text editor removed a bunch of whitespace.
Jonatan Werpers <jonatan@werpers.com>
parents:
105
diff
changeset
|
253 m = length(D1); |
06c3034966b7
Added and changed some comments. Also my text editor removed a bunch of whitespace.
Jonatan Werpers <jonatan@werpers.com>
parents:
105
diff
changeset
|
254 t = linspace(0,1,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 end |
107
06c3034966b7
Added and changed some comments. Also my text editor removed a bunch of whitespace.
Jonatan Werpers <jonatan@werpers.com>
parents:
105
diff
changeset
|
262 |
0 | 263 function obj = line(p1, p2) |
264 | |
265 function v = g_fun(t) | |
266 v(1,:) = p1(1) + t.*(p2(1)-p1(1)); | |
267 v(2,:) = p1(2) + t.*(p2(2)-p1(2)); | |
268 end | |
269 g = @g_fun; | |
270 | |
248
81e0ead29431
Fixed package names in +parametrization
Jonatan Werpers <jonatan@werpers.com>
parents:
151
diff
changeset
|
271 obj = parametrization.Curve(g); |
0 | 272 end |
273 | |
274 function obj = circle(c,r,phi) | |
275 default_arg('phi',[0; 2*pi]) | |
276 default_arg('c',[0; 0]) | |
277 default_arg('r',1) | |
278 | |
279 function v = g_fun(t) | |
280 w = phi(1)+t*(phi(2)-phi(1)); | |
281 v(1,:) = c(1) + r*cos(w); | |
282 v(2,:) = c(2) + r*sin(w); | |
283 end | |
284 | |
285 function v = g_fun_deriv(t) | |
286 w = phi(1)+t*(phi(2)-phi(1)); | |
287 v(1,:) = -(phi(2)-phi(1))*r*sin(w); | |
288 v(2,:) = (phi(2)-phi(1))*r*cos(w); | |
289 end | |
290 | |
248
81e0ead29431
Fixed package names in +parametrization
Jonatan Werpers <jonatan@werpers.com>
parents:
151
diff
changeset
|
291 obj = parametrization.Curve(@g_fun,@g_fun_deriv); |
0 | 292 end |
293 | |
294 function obj = bezier(p0, p1, p2, p3) | |
295 function v = g_fun(t) | |
296 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); | |
297 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); | |
298 end | |
299 | |
300 function v = g_fun_deriv(t) | |
301 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)); | |
302 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)); | |
303 end | |
304 | |
248
81e0ead29431
Fixed package names in +parametrization
Jonatan Werpers <jonatan@werpers.com>
parents:
151
diff
changeset
|
305 obj = parametrization.Curve(@g_fun,@g_fun_deriv); |
0 | 306 end |
307 | |
308 | |
309 function [g_out,gp_out] = transform_g(g,gp,tr) | |
310 A = tr.A; | |
311 b = tr.b; | |
312 flip = tr.flip; | |
313 | |
314 function v = g_fun_noflip(t) | |
315 % v = A*g + b | |
316 x = g(t); | |
317 | |
318 v(1,:) = A(1,:)*x+b(1); | |
319 v(2,:) = A(2,:)*x+b(2); | |
320 end | |
321 | |
322 function v = g_fun_flip(t) | |
323 % v = A*g + b | |
324 x = g(1-t); | |
325 | |
326 v(1,:) = A(1,:)*x+b(1); | |
327 v(2,:) = A(2,:)*x+b(2); | |
328 end | |
329 | |
330 | |
331 switch flip | |
332 case 1 | |
333 g_out = @g_fun_noflip; | |
334 gp_out = @(t)A*gp(t); | |
335 case -1 | |
336 g_out = @g_fun_flip; | |
337 gp_out = @(t)-A*gp(1-t); | |
338 end | |
339 end | |
340 | |
107
06c3034966b7
Added and changed some comments. Also my text editor removed a bunch of whitespace.
Jonatan Werpers <jonatan@werpers.com>
parents:
105
diff
changeset
|
341 end |
0 | 342 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
|
343 |
107
06c3034966b7
Added and changed some comments. Also my text editor removed a bunch of whitespace.
Jonatan Werpers <jonatan@werpers.com>
parents:
105
diff
changeset
|
344 |
06c3034966b7
Added and changed some comments. Also my text editor removed a bunch of whitespace.
Jonatan Werpers <jonatan@werpers.com>
parents:
105
diff
changeset
|
345 |
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
|
346 function g_norm = normalize(g0) |
107
06c3034966b7
Added and changed some comments. Also my text editor removed a bunch of whitespace.
Jonatan Werpers <jonatan@werpers.com>
parents:
105
diff
changeset
|
347 g1 = g0(1,:); |
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
|
348 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
|
349 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
|
350 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
|
351 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
|
352 |
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
|
353 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
|
354 % 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
|
355 % 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
|
356 |
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 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
|
358 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
|
359 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
|
360 'a and b must have same length, unless one is a scalar.'); |
107
06c3034966b7
Added and changed some comments. Also my text editor removed a bunch of whitespace.
Jonatan Werpers <jonatan@werpers.com>
parents:
105
diff
changeset
|
361 |
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
|
362 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
|
363 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
|
364 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
|
365 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
|
366 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
|
367 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
|
368 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
|
369 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
|
370 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
|
371 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
|
372 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
|
373 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
|
374 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
|
375 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
|
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 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
|
379 |
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 % 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
|
381 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
|
382 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
|
383 [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
|
384 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
|
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 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
|
387 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
|
388 end |