Matlab画带箭头的图

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

效果:
在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值