comparison +grid/Curve.m @ 105:1df4f3704b76 feature/arclen-param

Added error checking for all methods that use the derivative gp. Removed that from the to do list. Updated some comments.
author Martin Almquist <martin.almquist@it.uu.se>
date Mon, 07 Dec 2015 18:51:41 +0100
parents ffd9e68f63cc
children 06c3034966b7
comparison
equal deleted inserted replaced
104:ffd9e68f63cc 105:1df4f3704b76
5 transformation 5 transformation
6 6
7 end 7 end
8 methods 8 methods
9 %TODO: 9 %TODO:
10 % Errors or FD if there is no derivative function added.
11
12 % Concatenation of curves 10 % Concatenation of curves
13 % Subsections of curves 11 % Subsections of curves
14 % Stretching of curve parameter - semi-done 12 % Stretching of curve parameter - done for arc length.
15 % Curve to cell array of linesegments 13 % Curve to cell array of linesegments
16 14
17 % The curve parameter t must be in [0,1]. 15 % The curve parameter t must be in [0,1].
18 % Can supply derivative. 16 % Can supply derivative.
19 function obj = Curve(g,gp,transformation) 17 function obj = Curve(g,gp,transformation)
33 obj.transformation = transformation; 31 obj.transformation = transformation;
34 32
35 end 33 end
36 34
37 function n = normal(obj,t) 35 function n = normal(obj,t)
36 assert(~isempty(obj.gp),'Curve has no derivative!');
38 deriv = obj.gp(t); 37 deriv = obj.gp(t);
39 normalization = sqrt(sum(deriv.^2,1)); 38 normalization = sqrt(sum(deriv.^2,1));
40 n = [-deriv(2,:)./normalization; deriv(1,:)./normalization]; 39 n = [-deriv(2,:)./normalization; deriv(1,:)./normalization];
41 end 40 end
42 41
91 end 90 end
92 91
93 % Arc length parameterization. 92 % Arc length parameterization.
94 function curve = arcLengthParametrization(obj,N) 93 function curve = arcLengthParametrization(obj,N)
95 default_arg('N',100); 94 default_arg('N',100);
95 assert(~isempty(obj.gp),'Curve has no derivative!');
96 96
97 % Construct arcLength function using splines 97 % Construct arcLength function using splines
98 tvec = linspace(0,1,N); 98 tvec = linspace(0,1,N);
99 arcVec = obj.arcLength(0,tvec); 99 arcVec = obj.arcLength(0,tvec);
100 tFunc = spline(arcVec,tvec); % t as a function of arcLength 100 tFunc = spline(arcVec,tvec); % t as a function of arcLength