Monday 9 September 2019

trigonometry - 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?


Answer



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.



This is equivalent to take a scatter plot of points, finding their "center of mass" (or barycenter) and drawing an angle from the origin to the COM.




pic



$$\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.


No comments:

Post a Comment

real analysis - How to find $lim_{hrightarrow 0}frac{sin(ha)}{h}$

How to find $\lim_{h\rightarrow 0}\frac{\sin(ha)}{h}$ without lhopital rule? I know when I use lhopital I easy get $$ \lim_{h\rightarrow 0}...