View Single Post
Old Jun 4th, 2005, 6:39 AM   #9
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,318
Rep Power: 5 grumpy will become famous soon enough
The mean of 359.99 and 0.01 is 180.0 last I checked.

Assuming your individual angles are in the range [0, 360), what you need to do is something like this;
1) Compute the mean
2) Convert the angles so they are in the range [-180, 180). Compute the mean of those and add 180.
3) If the two values are the same (within machine precision), this is your mean.
4) If the values are different, convert the angles so they are in the range [90, 450). Compute the mean and subtract 90. As a sanity check, this value should be the same (within machine precision) as one of the previous two. This is your desired result.

I'll leave it as an exercise for you to explain why this will work (and why the four steps are needed)
grumpy is offline   Reply With Quote