RE: [Flightgear-devel] Heading error calculation [brain exercise]

```> > 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```
```

Thanks, Jorge, for the answer I was looking for, as well is for ignoring my
re-definition that a complete circle goes from 0 to 260 (See above ...
Ooops!).

Jon

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