你最好的办法是依靠一个内置的极性绘图功能做到这一点。我认为与您的需求最相似的是compass。它基本上绘制了一个箭头,从中心指向一个极坐标图上的一个点(以笛卡尔坐标定义)。
theta = deg2rad(130);
% Your speed in m/s
speed = 5;
hax = axes();
c = compass(hax, speed * cos(theta), speed * sin(theta));
% Change the view to orient the axes the way you've drawn
view([90 -90])
然后为了改变轴承和速度,你只需再次与你的新的轴承/速来电compass功能。
new_theta = deg2rad(new_angle_degrees);
c = compass(hax, new_speed * cos(new_theta), new_speed * sin(new_theta));
其他极性绘图选项包括polar和polarplot其接受极坐标,但没有一个箭头。如果你不喜欢极坐标图,你可以在笛卡尔坐标轴上始终使用quiver(确保指定相同的坐标轴)。
编辑 根据您的反馈和请求,以下是距离行驶极坐标图的示例。
% Speed in m/s
speed = 5;
% Time in seconds
time = 1.5;
% Bearing in degrees
theta = 130;
hax = axes();
% Specify polar line from origin (0,0) to target position (bearing, distance)
hpolar = polar(hax, [0 deg2rad(theta)], [0 speed * time], '-o');
% Ensure the axis looks as you mentioned in your question
view([90 -90]);
我们更新此情节与新的轴承,速度,时间,你会简单地调用polar再次指定轴。
hpolar = polar(hax, [0 theta], [0 speed], '-o');