![]() |
|
Math: Averaging an arbitary number of angles |
Fladimir da Gorf
Member #1,565
October 2001
![]() |
OK, there should be a simple answer to this - how can I get the average of an arbitarily large set of angles? It's clear how to average 2 angles - along the smallest angle between them, but how about a larger set? Also, what'll be the result then if the averaged angles are 0, PI/2, PI and 3PI/2? OpenLayer has reached a random SVN version number ;) | Online manual | Installation video!| MSVC projects now possible with cmake | Now alvailable as a Dev-C++ Devpack! (Thanks to Kotori) |
kazzmir
Member #1,786
December 2001
![]() |
Hm, is it something like taking the average of all the cosines, average of all the sines, then convert the resulting unit coordinate back into an angle? atan2( average(sines), average(cosines) );
|
Fladimir da Gorf
Member #1,565
October 2001
![]() |
Oh what an evil solution, I like it! That's a bit computationally expensive, though (this is for a very limited device), so if there's any other ways which don't include using trigonometric functions, it'd be great. OpenLayer has reached a random SVN version number ;) | Online manual | Installation video!| MSVC projects now possible with cmake | Now alvailable as a Dev-C++ Devpack! (Thanks to Kotori) |
Matthew Leverton
Supreme Loser
January 1999
![]() |
Edit: btw, Kazzmir's approach is what I would have suggested, although you can just use the sums. |
kazzmir
Member #1,786
December 2001
![]() |
Although if you just convert all the angles to be between -pi and pi you can just average the values directly, I think. Here is a stupid little ruby script to do it
|
Fladimir da Gorf
Member #1,565
October 2001
![]() |
ML, yeah, that's the basic average function for linear values, but angles are cyclic. When averaging angles like 10 and 350 decrees, the result, with that equation, would be 180 decrees, which isn't right... For the application, let's just say that it's geodata related OpenLayer has reached a random SVN version number ;) | Online manual | Installation video!| MSVC projects now possible with cmake | Now alvailable as a Dev-C++ Devpack! (Thanks to Kotori) |
kazzmir
Member #1,786
December 2001
![]() |
Oh it doesn't work if you average it from -pi to pi, but it does seem to work with my original method( the lines that are commented in the above code ). |
ImLeftFooted
Member #3,935
October 2003
![]() |
I read the thread title as |
nonnus29
Member #2,606
August 2002
![]() |
I spent about a month trying to do trig on the gameboy color a long time ago, and depending on just how limited of a device you're talking about; how about using trig functions with lookup tables or Cordic functions? |
Matthew Leverton
Supreme Loser
January 1999
![]() |
Quote:
For the application, let's just say that it's geodata related I wondered because if you have the data stored as vectors, it's a trivial solution. But I suppose then you wouldn't be asking. |
SiegeLord
Member #7,827
October 2006
![]() |
I made a nice angle subtraction function for my ChristMass hack entry, so I figured that it would work here. My method incrementally averages the angles by subtracting each successive angle from the average (using my function) and creating a new angle that is in the same revolution as the current average angle. The current average angle and this new angle are then averaged (the average angle is obviously weighed). Not sure if this is mathematically accurate, but my little test program seemed to show this to work well.
"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
Fladimir da Gorf
Member #1,565
October 2001
![]() |
Yes indeed, it works, because: ii * avg(ii-1) = ii * ((ii-1) * avg(ii-2) + angle[ii-1])/ii Thanks a lot! OpenLayer has reached a random SVN version number ;) | Online manual | Installation video!| MSVC projects now possible with cmake | Now alvailable as a Dev-C++ Devpack! (Thanks to Kotori) |
|