clear;
close all;
clc
n=10;%点的个数
x=5.*rand(n,2);%随机生成点
scatter(x(:,1),x(:,2),'filled');
for i=2:n
draw_arrow(x(i-1,:), x(i,:));
end
draw_arrow(x(n,:), x(1,:));
text(x(:,1),x(:,2),arrayfun(@(x)[' ' num2str(x)],1:n,'UniformOutput',0))
function draw_arrow(start_point, end_point)
% 从start_point到end_point画一箭头
K = 0.05; %箭头比例系数
theta = pi / 8; %箭头角度
A1 = [cos(theta), -sin(theta);
sin(theta), cos(theta)]; %旋转矩阵
theta = -theta;
A2 = [cos(theta), -sin(theta);
sin(theta), cos(theta)]; %旋转矩阵
arrow = start_point' - end_point';
arrow_1 = A1 * arrow;
arrow_2 = A2 * arrow;
arrow_1 = K * arrow_1 + end_point';
arrow_2 = K * arrow_2 + end_point';
hold on;
grid on;
plot([start_point(1), end_point(1)], [start_point(2), end_point(2)], 'k');
plot([arrow_1(1), end_point(1)], [arrow_1(2), end_point(2)], 'k');
plot([arrow_2(1), end_point(1)], [arrow_2(2), end_point(2)], 'k');
end
效果: