5
$\begingroup$

I'm trying to understand the maths behind this Fast fixed-point $\tt atan2$ calculation with self-normalization. In particular, equation $(2)$ for theta1 appears to provide a first-degree expansion of some series. Similarly, equation $(2a)$ under "QUICK NOTE" seems to expand this series.

  • What is the series that's being expanded?
  • How exactly is equation $(2)$ derived?
$\endgroup$
2
$\begingroup$

it's an approximation.

a better approximation is in this answer:

$$ \arctan(u) \approx \frac{u}{f(u^2)} \quad \quad -1 \le u \le 1 $$

where

$$ \begin{align} f(u^2)& = \sum\limits_{n=0}^{4} \ a_n \ u^{2n} \\ a_0 & = 1.0 \\ a_1 & = 0.33288950512027 \\ a_2 & = -0.08467922817644 \\ a_3 & = 0.03252232640125 \\ a_4 & = -0.00749305860992 \\ \end{align} $$

not as fast, but quite accurate. not bit-perfect accurate, but very accurate.

for atan2(), you need to put it in the correct tilted quadrant:

$$ \operatorname{atan2}(y,x) = \arg\{ x + j\,y \} = \begin{cases} \arctan\left(\frac{y}{x}\right) &\text{if } 0 < |y| \le x, \\ \frac{\pi}{2} - \arctan\left(\frac{x}{y}\right) &\text{if } 0 < |x| \le y, \\ -\frac{\pi}{2} - \arctan\left(\frac{x}{y}\right) &\text{if } y \le -|x| < 0, \\ \arctan\left(\frac{y}{x}\right) \pm \pi &\text{if } x \le -|y| < 0, \\ \text{undefined} &\text{if } x = 0 \text{ and } y = 0. \end{cases} $$

this will require two fixed-point divisions, but you can arrange it so that the result is always no greater than 1 in magnitude (the numerator is always smaller in magnitude than the denominator).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.