-
Notifications
You must be signed in to change notification settings - Fork 0
/
extendIntPoints.m
42 lines (40 loc) · 1.77 KB
/
extendIntPoints.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
function morecLines = extendIntPoints(intPoints, world)
n=1;
morecLines = cell(1,numel(intPoints));
for i = 1:length(intPoints(:,1))
for j = 1:length(intPoints(:,1))
[~, iInVertices] = ismember(intPoints(i,:), world.vertices, 'rows');
iInVertices = iInVertices + 1;
worldLoop = [world.vertices(end-2,:); world.vertices; world.vertices(2,:)];
if ~any(ismember(intPoints(j,:), worldLoop(iInVertices-1:iInVertices+1,:), 'rows'))
los = [intPoints(i,:); intPoints(j,:)];
%check if both sides of los are clear
intx = lineSegmentIntersect({los}, world.edges);
xi = intx.intMatrixX(intx.intAdjacencyMatrix)';
yi = intx.intMatrixY(intx.intAdjacencyMatrix)';
intxs = round([xi yi], 6);
mp = midPoint(los(1,:), los(2,:));
% ph = plot(los(:,1), los(:,2), 'k*');
% los
% conditions = [
% isempty(setdiff(intxs, los, 'rows'));
% inpolygon(mp(1), mp(2), world.vertices(:,1), world.vertices(:,2));
% checkBothSides(los, world)]
% pause(5);
% delete(ph);
if isempty(setdiff(intxs, los, 'rows')) &&...
inpolygon(mp(1), mp(2), world.vertices(:,1), world.vertices(:,2)) &&...
checkBothSides(los, world)
possible1 = extendLine(los, world);
possible2 = extendLine(flipud(los), world);
if all(size(possible1) == [2,2]) && all(size(possible2) == [2,2])
morecLines{n} = possible1;
n=n+1;
morecLines{n} = possible2;
n=n+1;
end
end
end
end
end
end