Most of the time.
So, recently we’ve had a project involving x & z motion, using a few servo drives and some controllers.
The problem came up, that we needed to average 3 angles together, to find a proper location to move…
So, this introduces an excellent time for real math…
Lets take for example this:
Average the following Angles: 0,359,1. The expected answer is actually 0 . Not, 120.
Why? because we care about the Direction, Not the Amount of Rotation actually moved.
So… This is where you actually get to use those trig fuctions to turn everything into vectors…
(cos(359),sin(359)) = (0.999, -0.0175)
(cos(0),sin(0)) = (1, 0)
(cos(1),sin(1)) = (0.999, 0.0175)
Now if we add these vectors and divide by 3, we get
(V1+V2+V3)/3 = (2.998/3, 0) = (0.999, 0)
and then find the direction of the vector given.
tan^-1 of 0 = 0;
Therefore we have an Average of 0 Degree’s in vector direction.
The only problem is, when you have two completely opposing directions. Which for my implementation never happened, but it needed to be accounted for if things when haywire.
If have you a Direction of 180, and 0 then those cancel each other. and you have a null vector. This could create a problem for some implements, but just keep track of them, remove them from the average, before vectorizing, and then take the sample count down by 1.
So, there you have it, a use for trig finally on how to average Angles as a Direction.
