# Does atan2(mean sine, mean cosine) approximate the mean angle?

I need to find an approximation for the sine and cosine of a rotation angle $\bar{\theta}$ such that:

$\bar{\theta} = \frac{1}{n}\sum\limits_{i=1}^{n}\theta_i$

I know each $s_i = \sin(\theta_i)$ and $c_i = \cos(\theta_i)$

But I want to do it without using $\arcsin(\theta_i)$ or $\arccos(\theta_i)$

My current approach is to get the mean sines and cosines; and normalize them:

$\sin(\tilde{\theta}) = \frac{1}{\alpha \,n}\sum s_i$

$\cos(\tilde{\theta}) = \frac{1}{\alpha \,n}\sum c_i$

choose $\alpha$ such that

$\sin(\tilde{\theta})^2 + \cos(\tilde{\theta})^2 = 1$

If I am not mistaken, what I get from this is

$\tilde{\theta} = \text{atan2}\left(\frac{1}{n}\sum s_i\,,\frac{1}{n}\sum c_i\right)$

I want to know if this actually approximates $\bar{\theta}$ for any set of values $\theta_i$

What I have tried

For the particular case where $\forall i; \;\theta_i\in\left]-\frac{\pi}{2},\frac{\pi}{2}\right[$

$\forall i; \;\cos(\theta_i)>0$

$\tan(\tilde{\theta}) = \frac{A}{B}; \; B>0$

By adding a new $\theta_k$ we have

$\tan(\tilde{\theta})^* = \frac{A+\frac{1}{n}s_k}{B+\frac{1}{n}c_k} = \frac{n\,A+s_k}{n\,B+c_k}$

$\frac{s_k}{c_k} = \frac{A}{B} \Rightarrow \frac{s_k}{c_k} = \tan(\tilde{\theta})^* = \frac{A}{B}$

$\frac{s_k}{c_k} > \frac{A}{B} \Rightarrow \frac{s_k}{c_k} > \tan(\tilde{\theta})^* > \frac{A}{B}$

$\frac{s_k}{c_k} < \frac{A}{B} \Rightarrow \frac{s_k}{c_k} < \tan(\tilde{\theta})^* < \frac{A}{B}$

So if every angle is between $-90^o$ and $90^o$ my approximation give a consistent result. (I think it works as well for angles between $90^o$ and $270^o$)

But how about the general case? When we can not assume the signs of $\sin(\theta_i)$ and $\cos(\theta_i)$? And when the tangent function is not monotonic?

• $\sin(\overline\theta)^2 + \cos(\overline\theta)^2$ is always $1$.
– user307169
Oct 30 '17 at 12:50
• @tilper That's why I must normalize those expressions. Oct 30 '17 at 12:56
• There's no reason to believe that this will approximate the "mean angle", sine and cosines do not linearly vary as their argument varies linearly. Believing that taking mean of the sines and cosines would give the mean angle is basically believing that sines and cosines do approximately vary linearly, but as you can see from their graphs, they don't quite Oct 30 '17 at 13:02
• There is no need to divide by $n$. Since atan2 calculates ratios of the arguments you can simplify things with $$\tilde{\theta} = {\rm atan2}\left(\sum s_i\,,\sum c_i\right)$$ Oct 30 '17 at 13:07
• @user340297 I understand it will not be the actual mean angle, but I hope it would give a consistent value, as it gives for the particular case I presented. What I mean from consistent is that if I add a angle, the approximation always gives an intermediary value. Oct 30 '17 at 13:07

I think you got it. To get an average angle, do not do $\frac{1}{n} \sum_i^n \theta_i$ but use the atan2() function with the average sine and cosine.
$$\tilde{\theta} = {\rm atan2}\left( \sum_i^n y_i, \sum_i^n x_i \right)$$
In the extreme case that $\tilde{x} \approx 0$ and $\tilde{y} \approx 0$ that average angle is going to have lots of uncertainty associated with it. This is because the scatter of points is near the origin and the location angle isn't well defined.