4
$\begingroup$

I am familiar with the basics of atan2. The doubt I have in the computation of atan2 came across from an image processing sofware.

This is a portion of the code segment when x>y. x and y are absolute values.

const_1 = 57.2836266;

const_2 = -18.6674461;

const_3 = 8.91400051;

const_4 = -2.53972459;

c = sqrt(y/x);

c2 = c*c;

angleInTheta = (((const_4*c2 + const_3)*c2 + const_2)*c2 + const_1)*c;

What confuses me is the formula of angleInTheta. The results are perfectly correct when applied. I would like to know get a brief explanation of this formula.

Thanks,

1 Answers 1

5

This produces a not-too-bad approximation to $\dfrac{180}{\pi} \arctan(\sqrt{y/x})$ for $0 < y < x$. I suppose the $x$ and $y$ are squares of the actual coordinate values. If you call your function $f(\sqrt{y/x})$, it appears that $f(t)/t$ is close to a best uniform approximation of $\dfrac{180}{\pi} \dfrac{\arctan(t)}{t}$ on the interval $[-1,1]$ by polynomials of degree $6$. That best approximation would have coefficients 57.28492047, -18.69087134, 8.976572844, 2.581481000, according to Maple.

  • 1
    The wikipedia article on [approximation theory](http://en.wikipedia.org/wiki/Approximation_theory) may be useful if you wish to understand this answer. Plot the difference between the two functions on $[-1.1]$ and see for youself.2012-06-18
  • 0
    Does Maple have a built-in function for finding the best approximation?2012-06-18
  • 0
    Yes, minimax in the numapprox package.2012-06-18
  • 0
    Thanks for the quick reply. This seems interesting. How were the approximations obtained. The whole complicated equation was reduced to such a easy-to-read approximation! Is there some very simple logic to arctan that I am missing. Could you share me any link related to this. sorry, I do not have enough reps to 'vote-up' your answer. :(2012-06-18
  • 0
    @AnoopKP: If you cannot vote it up, you can at least accept it. (At least, so I think.)2012-06-18
  • 0
    There is nothing special to arctan here, except that it is a continuous function and is odd (i.e. $\arctan(-x) = -\arctan(x)$).2012-06-18
  • 0
    yes Harald, I will DEFINITELY upvote it. I was just waiting for the reply to my doubt and Googling to get more info based on the answer by Robert. :)2012-06-18
  • 0
    arctan(X) = X - (X^3 /3) + (X^5 /5) + ... But how were the coefficient values 57.2849 etc. Am I looking into two completely different approaches.?2012-06-18
  • 1
    They were calculated by Maple's minimax function, which uses the Remez algorithm. http://en.wikipedia.org/wiki/Remez_algorithm2012-06-18
  • 0
    Thanks Robert and Harald for the help. The links helped me to have a jump start in this field. Though I stumbled upon this unknowingly, the approximations fascinated me and I started digging through this field of mathematics! :)2012-06-19