How to compute an average in a modular arithmetics?

135 Views Asked by At

I have a set of vectors represented as $(x1,y1,x2,y2)$ and would like to compute average direction of a flow. Simple average of $atan(x,y)$ would cause problems with modular arithmetic.A simple average of atan(x,y) values of vectors pointing at $-0.999\cdot\pi$ and $0.999\cdot\pi$ returns $0$, but should return $\pi$ instead.

I can probably vary angle in range (-180,-179,..179), and minimize it for deviation from vectors. Then use it as a crude offset to get away from discontinuity.

What is the right way to compute an average in a field of reminders like the direction of a vector?

1

There are 1 best solutions below

2
On BEST ANSWER

For vectors, I'd go for averaging those vectors in $\mathbb{R}^2$ and then normalizing the length. If all of the vectors are concentrated on the same side of the circle, it will return something on that side of the circle.

If it's specifically an angle you want, then you take the angle of that averaged vector; I assume that atan(x,y) is a function that does this with a full $2\pi$ range, rather than the $\pi$ range of the one-argument arctangent? Just apply that function after taking an average instead of before.

If the points are evenly spaced around the circle, the average vector will be zero and the process will fail. There's really no right answer in that case - every point on the circle has an equal claim to being the average.