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

问题描述:

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

这里的展示之类的话,我想画一幅画:

去除死ImageShack的链接

颤抖()绘图功能绘制这样的箭头。取你的theta值并将其转换为(x,y)笛卡尔坐标,表示想要绘制为箭头的矢量,并将它们用作(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]); 

通过在线看看Matlab文档来查看其他图类型;有很多,包括几个径向图。他们在MATLAB>函数>图形>专业绘图部分。在命令行执行“doc颤抖”并浏览。

这里的一个局部的答案,我希望你能找出休息。我启动了数字编辑器并打开了绘图工具。我从调色板中拖出一个箭头到我的身影上。然后我生成了一个m文件。这包括:

注释(图1,'箭头',[0.1489 0.2945],[0.5793 0.6481]);

所以,第一对坐标是箭头的开始。你将不得不使用一点点三角函数来确定尖端(第二对坐标)。你甚至可以得到小圆弧,如果你做一些更多的绘图工具。

让我们知道三角触发了你。哦,我忘了画点,但我想你可以弄清楚这一点吗?

如果你想尝试做一些看起来像你链接到图像,这里的一些代码,以帮助你做到这一点(注:你必须首先通过Erik JohnsonMathWorks File Exchange下载提交arrow.m,该我总是喜欢用生成任何形状和尺寸)的箭头:

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 

这里是它会是什么样子:

enter image description here

然后,您可以使用text函数将文本添加到绘图(对于角度和坐标值)。