That just seems to move the problem point. Take 178, 179, 181 and 182. Becomes 178, 179, -179, -178, average is 0. Or am I misunderstanding the algorithm? Kerry IVP wrote: >> are 0, 1, 359. Then a simple average is 120, but the number I'm >> looking for is zero >> =20 > > You'll have to treat a range as negative. Look at the circle as left > and right semi-circles > > For example, if the values were all between 0 and 180 then the > result will be "positive", ie the average will be Eastward. If one is > over 180 then that is going to skew the average Westward. And > similarly if all the values but one were between 180 and 360 > > Consider the way values are handled in a micro. 127 is the most > positive, 128 is the most negative. For values that represent degrees, > 0 is the least positive, 179 is the most positive, 180 is the most > negative, 359 is the least negative. In this case wrt North, or 0 > degrees, which is where the circle starts and ends > > So, 0, 1, 359 becomes 0, 1 and -1. The -1 is derived from 359 > by (360 - value) if (value > 179) and designating it negative > > Example ; 0, 137, 245 becomes 0, 137, -115, and the average > is +22, which is East of North > > Joe > =20 --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .