# Re: [Flightgear-devel] Heading error calculation [brain exercise]

```On Sun, 2 May 2004 08:01:20 -0500
Jon Berndt wrote:

> Does anyone know of a simple algorithm to calculate the difference between
> the desired heading and the actual heading, where the angle is given in
> degrees from 0 to 260? The stipulations are that the result must be <= 180.
> For example, you can go from 60 to 340 degrees (counter-clockwise), 110 to
> 280 (clockwise), 290 to 40 (clockwise), etc.  The desired result in the
> first case is -80, in the second case, 170, and for the last case, 110.  And
> so on ...
>
> The ideal algorithm will have the fewest trivial operations.```
```
desired heading - actual heading -> difference ( in the range -360 to +360)
if difference < -180 then add 360
if difference >180 then substract 360

--
Jorge Van Hemelryck

_______________________________________________
Flightgear-devel mailing list
[EMAIL PROTECTED]
http://mail.flightgear.org/mailman/listinfo/flightgear-devel
```