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

查看:333
本文介绍了如何在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>函数>图形>特殊绘图部分.在命令行中执行"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天全站免登陆