Plotting an intuitive graph of angles

删除回忆录丶 提交于 2019-12-23 13:11:32

问题


I'm trying to plot the heading of an object. I have four vectors of points - let's call them

  • mdex
  • mdey (aka x1,y1),
  • thpx
  • thpy (aka x2,y2).

I am finding the change in y and the change in x (dy and dx) and then entering that into the atan2d function. I then run through the results and plot them onto a chart.

The scale on the chart goes from -180 to 180. My problem arises when the line passes through -180 or 180 degrees. It then 'pops' to the opposite side of the graph (i.e. what would be 181 is actually -179).

This is problematic because it makes it look like there are massive shifts in angle when there really is not - it's just 'turning over'. Additionally, this screws up my angular velocity calculations, which are based on how much has changed between points. Originally, I just tried converting the graph to a 0-360 scale by adding 180 to all values that were below 0. This did not work.

Here's is the graph so you might understand the issue better (the graph is after I tried the 0-360 conversion).

My Question

I'm wondering if there's a different function I can use to calculate the angle that would give me a value that is ever increasing, a way to modify the data so that it plots nicely, or a way to modify the graph so it looks intuitive?

Thanks in advance!


回答1:


Use unwrap to remove the unwanted jumps. The argument must be in radians:

>> ang = [150 160 170 180 -170 -160] %// undesired jump from 180 to -180
ang =
   150   160   170   180  -170  -160

>> 180/pi * unwrap(ang * pi/180)
ans =
   150   160   170   180   190   200


来源:https://stackoverflow.com/questions/24783722/plotting-an-intuitive-graph-of-angles

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!