如何在MATLAB中显示以特定角度定位的箭头?

Aur*_*ien 13 matlab plot angle

我在MATLAB工作,我遇到了一个非常简单的问题:我有一个由其位置(x,y)theta(一个角度,以度为单位)定义的对象.我想绘制点并添加一个箭头,从该点开始并指向角度定义的方向.它实际上甚至不必是一个箭头,任何图形显示角度的值都会做!

这是一张图片,展示了我想要绘制的东西:

删除了死的ImageShack链接

And*_*nke 14

箭头()绘图功能绘制这样的箭头.取你的theta值并将其转换为(x,y)笛卡尔坐标,表示你想要绘制为箭头的矢量,并将它们用作quiver()的(u,v)参数.

theta = pi/9;
r = 3; % magnitude (length) of arrow to plot
x = 4; y = 5;
u = r * cos(theta); % convert polar (theta,r) to cartesian
v = r * sin(theta);
h = quiver(x,y,u,v);
set(gca, 'XLim', [1 10], 'YLim', [1 10]);
Run Code Online (Sandbox Code Playgroud)

在线查看Matlab文档以查看其他绘图类型; 有很多,包括几个径向地块.它们位于MATLAB>函数>图形>专用绘图部分.在命令行执行"doc quiver"并浏览.


gno*_*ice 8

如果你想尝试做一些看起来像你链接到图像,这里的一些代码,以帮助你做到这一点(注:你必须先下载提交arrow.m埃里克·约翰逊MathWorks的文件交换,这是我总是喜欢用来生成任何形状和大小的箭头):

x = 1;                          % X coordinate of arrow start
y = 2;                          % Y coordinate of arrow start
theta = pi/4;                   % Angle of arrow, from x-axis
L = 2;                          % Length of arrow
xEnd = x+L*cos(theta);          % X coordinate of arrow end
yEnd = y+L*sin(theta);          % Y coordinate of arrow end
points = linspace(0, theta);    % 100 points from 0 to theta
xCurve = x+(L/2).*cos(points);  % X coordinates of curve
yCurve = y+(L/2).*sin(points);  % Y coordinates of curve
plot(x+[-L L], [y y], '--k');   % Plot dashed line
hold on;                        % Add subsequent plots to the current axes
axis([x+[-L L] y+[-L L]]);      % Set axis limits
axis equal;                     % Make tick increments of each axis equal
arrow([x y], [xEnd yEnd]);      % Plot arrow
plot(xCurve, yCurve, '-k');     % Plot curve
plot(x, y, 'o', 'MarkerEdgeColor', 'k', 'MarkerFaceColor', 'w');  % Plot point
Run Code Online (Sandbox Code Playgroud)

这就是它的样子:

在此输入图像描述

然后,您可以使用该text功能将文本添加到绘图中(对于角度和坐标值).