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!
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With