# How do I best calculate angle differences when crossing the 360 axis? (Python) [closed]

I am trying to calculate the total number of turns of a vehicle over time to be a feature in the prediction of accident likelihood. Unfortunately, I am having issues solving the problem of crossing the 360/0 axis that comes from the nature of the problem. My original thought was - the unit circle - and changed all my degree data to the sin of itself. This creates a new problem of not being able to tell the difference between a large turn from 0 to 180 degrees or vice versa, from 2 turns one 90 degrees from 0 or 180 and back to the original location.

To put a picture of what I am trying to create here. This is a plot of degrees over time of one of the experiments. This should have 9 turns. 8 which are early turns followed by immediate ones in the opposite direction and a 9th turn which crosses the 360 axis. I am trying to consider any turn of more than 60 degrees within a short period as a "turn". Please help! Personally, I'd go about this with a `2 x len(time_series)` matrix with each column as a velocity timepoint (first row for latitudinal with positive being N and negative being S, and second row for longitudinal (+ E, - W)). You could also use polar coordinates for this, speed and azimuth. The other dimension (each column) would simply be time slices.