Files
MATLAB3/plotTour.m

40 lines
1.2 KiB
Mathematica
Raw Permalink Normal View History

2025-03-26 20:08:20 +08:00
function plotTour(positions, route)
%
% positions -
% route -
%
figure;
%
plot(positions(:, 2), positions(:, 3), 'o', 'MarkerSize', 8, 'MarkerFaceColor', 'blue');
hold on;
% 线
for i = 1:length(route)-1
current = route(i);
next = route(i+1);
% 线
line([positions(current, 2), positions(next, 2)], ...
[positions(current, 3), positions(next, 3)], ...
'Color', 'red', 'LineWidth', 1.5);
end
%
plot(positions(route(1), 2), positions(route(1), 3), 'gs', 'MarkerSize', 12, 'MarkerFaceColor', 'green');
%
for i = 1:size(positions, 1)
text(positions(i, 2), positions(i, 3), num2str(i), ...
'HorizontalAlignment', 'left', 'VerticalAlignment', 'bottom');
end
%
xlabel('X');
ylabel('Y');
title('');
grid on;
legend('', '', '/');
hold off;
end