如何在 MATLAB 中显示以特定角度定位的箭头? [英] How do I display an arrow positioned at a specific angle in MATLAB?

查看:27
本文介绍了如何在 MATLAB 中显示以特定角度定位的箭头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am working in MATLAB and I'm stuck on a very simple problem: I've got an object defined by its position (x,y) and theta (an angle, in degrees). I would like to plot the point and add an arrow, starting from the point and pointing toward the direction defined by the angle. It actually doesn't even have to be an arrow, anything graphically showing the value of the angle will do!

这是一张显示我想要画的东西的图片:

Here's a picture showing the kind of thing I'm trying to draw:

删除了无效的 ImageShack 链接

推荐答案

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

The quiver() plotting function plots arrows like this. Take your theta value and convert it to (x,y) cartesian coordinates representing the vector you want to plot as an arrow and use those as the (u,v) parameters to quiver().

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

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

Take a look through online the Matlab documentation to see other plot types; there's a lot, including several radial plots. They're in the MATLAB > Functions > Graphics > Specialized Plotting section. Do "doc quiver" at the command line and browse around.

这篇关于如何在 MATLAB 中显示以特定角度定位的箭头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆