Sum of arctangents

261 Views Asked by At

How can I get the sum of two arctangents that is not restricted to the range of $(-\pi, \pi]$?$$ \arctan\Bigl(\frac{y_1}{x_1}\Bigr) + \arctan\Bigl(\frac{y_2}{x_2}\Bigr) $$ I use $\operatorname{arctan2}(y,x)$ function for calculating the above arctangent function. I know that there is this $$\arctan u + \arctan v=\arctan\Bigl(\frac{u+v}{1−uv}\Bigr)$$ but it does not return the correct value for any x and y.

1

There are 1 best solutions below

1
On BEST ANSWER

Modulo $\pi$, we have $$\begin{align}\arctan\frac{y_1}{x_1}+\arctan\frac{y_2}{x_2}&=\arg(x_1+iy_1)+\arg(x_2+iy_2)\\ &=\arg\bigl((x_1+iy_1)(x_2+iy_2)\bigr)\\ &=\arg\bigl((x_1x_2-y_1y_2)+i(x_1y_2+x_2y_1)\bigr)\\ &=\arctan\frac{x_1y_2+x_2y_1}{x_1x_2-y_1y_2}\end{align}. $$ In order to cope with the possible error by multiples of $\pi$, it suffices to compute the original $\arctan$s very roughly (note that an error of $\pm.75$ per summand would not hurt!); in fact, just looking at the quadrants (i.e., signs of the $x_i,y_i$) is precise enough ...