'Interpolation function for compass bearings in python
Essentially, I have a CSV file full of compass bearings in radians from 0 to 2pi and attached timestamps that looks something like this:
- time, bearing
- 0.36,0.01
- 0.97,0.23
- 1.37,0.04
- 1.78,6.24
- 2.34,0.21
- ect.
Because these time values aren't very nice, I need to interpolate these values to every one full second. The problem is, that the bearing value can very quickly swap between 0 and 2pi - for example, in real life, if you're facing a bearing of 1 degree and then you turn to a bearing of 359 degrees, you're facing almost the same direction (only 2 degrees away from each other) - however, if you tell a computer to interpolate or average these values, it would return the average value between 1 degree and 359 degrees, which would be 180 degrees. But in reality, this is the complete opposite direction to the way you're facing. I'm trying to use scipy's interpolate function to do this, but I cannot logically think of a way to do it without running into the above problem.
The alternative solution which I've tried so far is to take the sin of each value and then try to interpolate using those. That wouldn't run into the above issue, because sin(359) would return a value very close to sin(1), and then interpolating between them would return sin(0). The issue with this method is that after I interpolate it I still need to end up with an angle, and using arcsin on the newly interpolated sin values will return an angle in the wrong quadrant a lot of the time.
Any help? Is there some built in function to scipy which I've missed?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|