[gdal-dev] How to calculate total change in headings?

Christopher Barker Chris.Barker at noaa.gov
Thu Feb 11 12:26:36 EST 2010


Roger André wrote:
> Not a GDAL question at all, but one which might amuse some of you, and 
> which has been unsolveable in a satisfactory fashion for me.

fun with circular math...

> Given a list of compass headings in degrees, how can you reliably 
> calculate the total change in direction?
> 
> Here's an example:  [355.5, 10.0, 5.1]

how do you define "total change in direction"? Wouldn't it be the 
difference between the first and the last, with the ones in the middle 
irrelevant. So in that example, it would be 9.6 degrees.

Also, which would you want: -90degrees or +270 degrees for a change from 
90 to 0 ?

Anyway, a start is simply to do the subtraction then do "mod" 360. In 
Python:

In [28]: (5.1 - 355.5) % 360
Out[28]: 9.6000000000000227

In [30]: (0 - 90) % 360
Out[30]: 270

you can subtract 360 for values over 180, if you want.

-Chris


-- 
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov


More information about the gdal-dev mailing list