-
Notifications
You must be signed in to change notification settings - Fork 13
/
addVerticalPoint.m
executable file
·48 lines (45 loc) · 1.24 KB
/
addVerticalPoint.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
function [X,Y,CptsNdx] = addVerticalPoint(X,Y,xc,CptsNdx);
%
% Add points in the polygon that are the intersection of the edges of the
% polygon with the vertical lines defines by xc
%
% Also, propagate the contact point label to the new points
%
% xc is a vector
bb = [min(X) max(X)];
delta = (bb(2)-bb(1))/100;
nc = length(xc);
ndx = [];
for m = 1:nc
X = [X; X(1)];
Y = [Y; Y(1)];
if nargin >3; CptsNdx = [CptsNdx; CptsNdx(1)]; end
np = length(X)-1;
% Search points (only add the point, if there is no point nearby)
Xn = [];
Yn = [];
Cn = [];
for i = 1:np
if min(X(i),X(i+1))+delta<=xc(m) & max(X(i),X(i+1))-delta>xc(m)
% Insert point
xx = xc(m);
yy = (Y(i+1)-Y(i))/(X(i+1)-X(i))*(xc(m)-X(i))+Y(i);
Xn = [Xn; X(i); xx];
Yn = [Yn; Y(i); yy];
if nargin > 3
Cn = [Cn; CptsNdx(i); CptsNdx(i)*CptsNdx(i+1)]; % the new point is a contact point if it is betwen two contact points
end
else
Xn = [Xn; X(i)];
Yn = [Yn; Y(i)];
if nargin >3
Cn = [Cn; CptsNdx(i)];
end
end
end
X = Xn;
Y = Yn;
if nargin >3
CptsNdx = Cn;
end
end