-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathline_segment.m
152 lines (119 loc) · 4.48 KB
/
line_segment.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
classdef line_segment
properties
x_start % x coordenate of the starting point
x_end % x coordenate of the end point
N % level of discretization (the total number of point on the bump is
p % degree of polinomial change of variable for Colton and Kress method
s
w
dw
x
dx
d2x
d3x
Np
win
normals
tau
name
end
methods
%--------------------------------------------------------------------------------------------%
function [x, dx,d2x,d3x] = param(obj,t)
x_s = obj.x_start;
x_e = obj.x_end;
% Parametrization of the curve between 0:2*pi
x = x_s+(x_e-x_s)*t/(2*pi);
dx = (x_e-x_s)/(2*pi);
d2x = [0 0];
d3x = [0 0];
end
%--------------------------------------------------------------------------------------------%
function obj = cctor(obj,N,x_s,x_e,percent)
% obj.x_start = x_s;
%
% obj.x_end = x_e;
%
% obj.N = N;
%
%
% obj.Np = 2*N-1;
% obj.p = 4;
% obj.s = pi/N*(1:1:2*N-1)';
% [obj.w,obj.dw] = W(obj.s,obj.p);
% Nt = 2*N-1;
%
%
% obj.x = zeros(Nt,2);
% obj.dx = zeros(Nt,2);
% obj.d2x = zeros(Nt,2);
% obj.d3x = zeros(Nt,2);
%
% obj.win = zeros(Nt,1);
% obj.normals = zeros(Nt,2);
% obj.tau = zeros(Nt,1);
%
% for i=1:Nt
%
% [obj.x(i,:),obj.dx(i,:),obj.d2x(i,:),obj.d3x(i,:)] = obj.param(obj.w(i));
%
% x0 = 0.5*(x_s+x_e);
% A = norm(x_e-x0);
%
% obj.win(i) =POU(norm(obj.x(i,:)-x0),A*percent,A);
%
% obj.tau(i) = norm(obj.dx(i,:));
%
% obj.normals(i,:) = [obj.dx(i,2) -obj.dx(i,1)]/obj.tau(i);
%
% end
%
% obj.name = 'line_segment';
obj.x_start = x_s;
obj.x_end = x_e;
obj.N = N;
obj.Np = 2*N;
obj.s = pi/N*(0:1:2*N-1)';
obj.w = obj.s;
obj.dw = ones(size(obj.s));
Nt = 2*N;
obj.x = zeros(Nt,2);
obj.dx = zeros(Nt,2);
obj.d2x = zeros(Nt,2);
obj.d3x = zeros(Nt,2);
obj.win = zeros(Nt,1);
obj.normals = zeros(Nt,2);
obj.tau = zeros(Nt,1);
for i=1:Nt
[obj.x(i,:),obj.dx(i,:),obj.d2x(i,:),obj.d3x(i,:)] = obj.param(obj.w(i));
x0 = 0.5*(x_s+x_e);
A = norm(x_e-x0);
obj.win(i) =POU(norm(obj.x(i,:)-x0),A*percent,A);
obj.tau(i) = norm(obj.dx(i,:));
obj.normals(i,:) = [obj.dx(i,2) -obj.dx(i,1)]/obj.tau(i);
end
obj.name = 'line_segment';
end
%-------------------------------------------------------------------------%
function [dist,xc,tc,rel_pos] = dist(obj,x)
% Position of the point x with respect to the curve is
% defined as follows:
%
% x
% Obove <------< : rel_pos = 1
%
%
% Below <------< : rel_pos = -1
% x
options = optimset ('TolX',1.0e-5);
f = @(t) norm(obj.param(t)-x);
[tc,dist] = fminbnd(f,0,2*pi,options);
[xc,dxc] = obj.param(tc);
dxc = [dxc 0];
d = [x-xc 0];
A = cross(d,dxc);
rel_pos = sign(A(3));
end
%-------------------------------------------------------------------------%
end
end