Maybe I'm thinking linearly too, but doesn't that just move the problem from North to South?
At a little SE its 179 or less, and move a little SW and it's -179 or more, which averages to 0 or North.
Maybe there's another trick in that hint?
<br>
Maybe I'm thinking linearly too, but doesn't that just move the problem from North to South?
At a little SE its 179 or less, and move a little SW and it's -179 or more, which averages to 0 or North.
Maybe there's another trick in that hint?
<br>
DT
What I'm thinkin...(without colons this time)
1st reading is 30 degrees, 2nd reading is 330 degrees, average wanted should be 0 degrees, obviously the AVERAGE is 180...no good...but...
if you take the sin and cos of 30, you get .5 and .866...
if you take the sin and cos of 330, you get -.5 and .866...
the average of the .5 and -.5 is 0, sin(0)=0 (average of .5 & -.5)...
but I'm stuck at what to do with the 2 cosine values. Maybe this example is just a 'special case' where the result is right one 'axis' lines of a graph...
More thought needed...I know the answer is right here...just have to put my finger on it...
Or maybe you could treat the first 30 degree reading as actually 390 (360 + 30), then do the averaging, which would give you the right answer of 360, subtract 360 from the result and you get the answer...
Last edited by skimask; - 6th July 2007 at 18:22.
Another prod...
You have two values, if the sum of the two values (each in the range 0-180, and ignoring if they're positive or negative) are equal to or greater than 180, then simply change the reference point.
Alternatively, how about this simplest solution... forget North, South or whatever, your reference point 'floats' - it's one of your two values (each 0-359)... ValueB is X degrees away from ValueA. So simply halve the difference and always add to ValueA. Note, that your choice of which value is ValueA is important... but then I'd be giving it away... once again it's something about if the difference is greater than 180...
Well there's two potential solutions... need any more?
Melanie taps her fingers impatiently whilst eyeing up her whip coiled on the wall, then scribbles...
There is only one 'anomaly' which could be adjusted whichever way you choose (although there is no true definitive answer). If ValueA and ValueB are exactly 180 degrees apart, you have two potential answers both of which are correct... eg ValueA is Zero and ValueB is 180, you have two answers - one being 90 and the other being 270. My little ditty above always selects the higher - 270 in this case. But what the hell do you expect for 30 seconds work?Code:ValueA var Word ValueB var Word ValueC var Word Result var Word If ValueA < ValueB then Swap ValueA,ValueB ValueC=ValueA-ValueB If ValueC < 180 then ValueC=ValueC/2 Result=ValueB+ValueC else ValueC=360-ValueC ValueC=ValueC/2 Result=ValueA+ValueC endif If Result = > 360 then Result=Result-360
Or, here's another possibility...Which treats anything in the range of 0-90 as if it's 360-450. But only if the other value is on the other side of the zero point.Code:Direction VAR WORD ; Holds the Averaged wind direction Sample VAR WORD AvgCount CON 3 ; Number of samples to average ; Get New Sample here 0-359 If (Direction > 270) AND (Sample < 90) then Sample = Sample + 360 else if (Direction < 90) AND (Sample > 270) then Direction = Direction + 360 endif endif Direction = ((Direction * (AvgCount-1) + Sample) / AvgCount) // 360
Then after averaging, it gets the Modulus of the result, which brings it back into the 0-359 range.
DT
If it is any help. The boys from Berkeley have an routine for averaging the anemometer direction. It is somewhat specific to their product, but the explanation may be of help. Has links to the math routines.
http://www.emesystems.com/OL2wind.htm#Wind_vane
ooooh... I don't like bashing other folks work, but that is very amateurish... "Hello Mr Customer. Here's a fine wind direction guage for your airfield - oh, by the way, (at best) it doesn't work 3% of the time..."
Bookmarks