Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Thomas Roy
Problemsquad2
Commits
76e13bb9
Commit
76e13bb9
authored
May 05, 2017
by
Thomas Roy
Browse files
legal path and corners
parent
f8deb196
Changes
4
Hide whitespace changes
Inline
Side-by-side
check_corner.m
0 → 100644
View file @
76e13bb9
function
corner
=
check_corner
(
i0
,
i1
,
A
,
y
)
m
=
size
(
y
,
1
);
C
=
zeros
(
m
);
C
(
1
:
m
-
2
,
1
:
m
-
2
)
=
A
;
D
=
C
'+
C
;
% going from x0 to x1
[
~
,
nodes
]
=
find
(
D
(
i1
,:));
nodes
=
nodes
(
nodes
~=
i0
);
%remove existing edge if it exists
j
=
1
;
theta
=
zeros
(
length
(
nodes
),
1
);
for
k
=
nodes
theta0
=
acos
(
dot
(
y
(
i0
,:)
-
y
(
i1
,:),
y
(
k
,:)
-
y
(
i1
,:))/(
sqrt
(
sum
(
abs
(
y
(
i0
,:)
-
y
(
i1
,:))
.^
2
))
*
D
(
k
,
i1
)));
thecross
=
cross
([
y
(
i0
,:)
-
y
(
i1
,:),
0
],
[
y
(
k
,:)
-
y
(
i1
,:),
0
]);
thesign
=
sign
(
thecross
(
3
));
if
thesign
<
0
theta
(
j
)
=
2
*
pi
-
theta0
;
else
theta
(
j
)
=
theta0
;
end
j
=
j
+
1
;
end
if
isempty
(
nodes
)
corner
=
0
;
else
corner
=
(
max
(
theta
)
-
min
(
theta
))
>
pi
;
end
end
legal_path.m
0 → 100644
View file @
76e13bb9
function
[
B
,
x
]
=
legal_path
(
A
,
x
)
% We generate n uniformly random points in [0,1]x[0,1]
% x = rand(n,2);
n
=
size
(
x
,
1
);
% Initialise Adjacency mantrix
B
=
zeros
(
n
+
2
);
% B(1:n,1:n) = A; % Only do upper triangular since symmetric
x
(
n
+
1
,:)
=
[
0
,
0
];
x
(
n
+
2
,:)
=
[
0.5
,
0.5
];
% A = A+A';
% First Line
% B(1,2) = norm(x(1,:)-x(2,:));
% Construct the graph
for
i
=
1
:
n
+
2
distances
=
sqrt
(
sum
(
abs
(
x
-
x
(
i
,:))
.^
2
,
2
));
[
distances
,
nodes
]
=
sort
(
distances
);
crosses
=
1
;
j
=
1
;
for
l
=
setdiff
(
1
:
n
+
2
,
i
)
node
=
nodes
(
j
);
d_min
=
distances
(
j
);
[
I
,
J
]
=
find
(
A
);
% Remove node included in current segment
J
=
J
(
I
~=
node
&
I
~=
i
);
I
=
I
(
I
~=
node
&
I
~=
i
);
I
=
I
(
J
~=
node
&
J
~=
i
);
J
=
J
(
J
~=
node
&
J
~=
i
);
for
k
=
1
:
length
(
I
)
crosses
=
checkCrossedLines
(
x
(
i
,:),
x
(
node
,:),
x
(
I
(
k
),:),
x
(
J
(
k
),:));
if
crosses
==
1
break
end
end
if
crosses
==
1
corners
=
1
;
else
% check if outgoing nodes are corners
node_corner
=
check_corner
(
i
,
node
,
A
+
A
'
,
x
);
outgoing_corner
=
check_corner
(
node
,
i
,
A
+
A
'
,
x
);
corners
=
node_corner
|
outgoing_corner
;
end
if
(
crosses
==
0
&&
corners
==
0
)
||
isempty
(
I
)
B
(
node
,
i
)
=
d_min
;
end
j
=
j
+
1
;
end
end
end
make_plot.m
View file @
76e13bb9
G = graph(A+A');
plot(G, 'XData',x(:,1),'YData',x(:,2))
figure
G = graph(B+B');
plot(G, 'XData',y(:,1),'YData',y(:,2))
hold on
G2 = graph(A+A');
plot(G2, 'XData',x(:,1),'YData',x(:,2))
xlim([0,1])
ylim([0,1])
\ No newline at end of file
shortest_path.m
View file @
76e13bb9
...
...
@@ -10,11 +10,11 @@ A(1,2) = norm(x(1,:)-x(2,:));
for
i
=
3
:
n
distances
=
sqrt
(
sum
(
abs
(
x
(
1
:
i
-
1
,:)
-
x
(
i
,:))
.^
2
,
2
));
[
distances
,
nodes
]
=
sort
(
distances
);
cross
=
1
;
cross
es
=
1
;
node
=
nodes
(
1
);
d_min
=
distances
(
1
);
j
=
1
;
while
cross
==
1
while
cross
es
==
1
[
I
,
J
]
=
find
(
A
(
1
:
i
-
1
,
1
:
i
-
1
));
% Remove node included in current segment
...
...
@@ -23,12 +23,12 @@ for i=3:n
I
=
I
(
J
~=
node
);
J
=
J
(
J
~=
node
);
for
k
=
1
:
length
(
I
)
cross
=
checkCrossedLines
(
x
(
i
,:),
x
(
node
,:),
x
(
I
(
k
),:),
x
(
J
(
k
),:));
if
cross
==
1
cross
es
=
checkCrossedLines
(
x
(
i
,:),
x
(
node
,:),
x
(
I
(
k
),:),
x
(
J
(
k
),:));
if
cross
es
==
1
break
end
end
if
cross
==
1
&&
~
isempty
(
I
)
if
cross
es
==
1
&&
~
isempty
(
I
)
j
=
j
+
1
;
node
=
nodes
(
j
);
d_min
=
distances
(
j
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment