How can I get the sum of two arctangents that is not restricted to the range of (-\pi,\pi]?

arrebolyt

arrebolyt

Answered question

2022-01-29

How can I get the sum of two arctangents that is not restricted to the range of (π,π]?
arctan(y1x1)+arctan(y2x2)
I use arctan2(y,x) function for calculating the above arctangent function. I know that there is this
arctanu+arctanv=arctan(u+v1uv)
but it does not return the correct value for any x and y.

Answer & Explanation

tsjutten20

tsjutten20

Beginner2022-01-30Added 13 answers

Modulo π, we have
arctany1x1+arctany2x2=arg(x1+iy1)+arg(x2+iy2)
=arg((x1+iy1)(x2+iy2))
=arg((x1x2y1y2)+i(x1y2+x2y1))
=arctanx1y2+x2y1x1x2y1y2
In order to cope with the possible error by multiples of π, it suffices to compute the original arctans very roughly (note that an error of ±.75 per summand would not hurt!); in fact, just looking at the quadrants (i.e., signs of the xi,yi) is precise enough

Do you have a similar question?

Recalculate according to your conditions!

Ask your question.
Get an expert answer.

Let our experts help you. Answer in as fast as 15 minutes.

Didn't find what you were looking for?