两点之间的有向箭头

比如我们需要画一条从A点到B点的有向箭头。

涉及知识点:

  • 矩阵的旋转 平移 缩放

1、main.m

% 根据两点坐标画箭头

clear;

close all;

start_point = [0, 0];

end_point = [3, 4];

draw_arrow(start_point, end_point);

2、draw_arrow.m

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;

axis equal;

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');

hold off;

3、运行结果

改变起点和终点的坐标,结果如下图所示。

1.《matlab如何在坐标内某一点画箭头》援引自互联网,旨在传递更多网络信息知识,仅代表作者本人观点,与本网站无关,侵删请联系页脚下方联系方式。

2.《matlab如何在坐标内某一点画箭头》仅供读者参考,本网站未对该内容进行证实,对其原创性、真实性、完整性、及时性不作任何保证。

3.文章转载时请保留本站内容来源地址,https://www.lu-xu.com/keji/3302872.html