Tuesday 10 June 2014

Signed angles

I wish I'd known MATLAB had... ATAN2

  • ATAN2 is the arctangent, but takes X and Y separately. It's not quite the same as ATAN(X/Y).
  • The problem with normal ATAN is that, because you are calculating X/Y, the function can't distinguish beween when both X and Y are positive, and when both X and Y are negative! So when an angle is returned, its range is only pi, not 2*pi. ATAN2 solves this problem.
  • ATAN2(X,Y) gives the angle in radians of a point (x,y) from the origin. The angle is measured from the horizontal line going rightwards, i.e. the positive x-axis. Positive angles go anticlockwise, and negative angles go clockwise from this line, pi and -pi both indicate points on the negative x-axis going leftwards, i.e. x is negative and y is 0.
  • ATAN2 is great because it is signed (+/-)! so you don't lose information.
  • Note that you can also do this easily with complex numbers:
   ATAN2(X,Y) is the same as   angle(X+1j*Y)

No comments:

Post a Comment