I'd like to ask your help for this problem: I have two bearings. These bearings are angle of direction from $-180$ to $+180$ degrees. One is between my current position $(A)$ and a target $(T)$. One is between my previous position $(P)$ and my current position $(A)$. I'd like to obtain a third one with the relative direction considering the direction I'm moving.
I try to explain better:
If I walk from south to north and my target is on the west (my left side), the bearing will be $-90$ degrees. But if I walk from north to south and the target is on west is on my right side, so bearing should be $+90$.
I tried to find a formula to obtaing this direction, but I'm not successful with it. Any suggestion is appreciated.
Thanks so much!
Assuming that current bearing has north being $0$, west being $-90$ and east being $90$, and you want the relative bearing (with straight ahead being $0$, left being $-90$ and right being $90$), then the formula is simply relative bearing $=$ target bearing minus current bearing, then adding or subtracting 360 as needed to bring the relative bearing back in the range $[-180, 180]$.
For instance, if your current bearing is $45$ (northeast) and the target bearing is $-45$, then the relative bearing is $-45 - 45 = -90$, or left. Second example: Current bearing is $-90$ (west), target bearing is $135$ (southeast), then relative bearing is $135-(-90) = 225$, then subtract $360$ to get $225-360 = -135$ (rear left).