Angle for tracking compass.

41 Views Asked by At

I am currently writing a tracking app that is able to get your currently facing angle and the angle to a destination and point an arrow in the direction you need to travel. (As the crow flies)

I am having trouble taking these 2 angles and making them work together so that the arrow points in the correct direction.

My knowledge of Mathematics is extremely limited so any help would be appreciated.

1

There are 1 best solutions below

2
On BEST ANSWER

Let $s$ denote the source heading.

Let $d$ denote the destination heading.

Then the desired heading is simply $(360+d-s)\bmod{360}$.


If you wish to avoid the use of "$\bmod$", then you can write it as:

$H(d,s)=360+d-s-360\cdot\left\lfloor\frac{360+d-s}{360}\right\rfloor$


If you wish to avoid the use of "$\left\lfloor\dots\right\rfloor$", then you can write it as:

$H(d,s)=\cases { d \geq s &$d-s$\\ d < s &$360+d-s$\\ } $


If you wish to avoid the use of "$\cases{\dots\\\dots\\}$", then you can write it as:

$H(d,s)=\sqrt[2]{(d-s)^2}$