0

Possible Duplicate:
what is the difference between atan and atan2 in c++ ?

Why is −π < atan2(y, x) ≤ π while for lines we really need only from 0 to π and what has api like atan2 but would return from 0 to pi?

Community
  • 1
  • 1
Rella
  • 65,003
  • 109
  • 363
  • 636
  • 1
    possible duplicate of [what is the difference between atan and atan2 in c++ ?](http://stackoverflow.com/questions/283406/what-is-the-difference-between-atan-and-atan2-in-c). It has "c++" in the title but all the answers apply to any language which exposes atan and atan2 – Flexo Feb 12 '11 at 18:03

2 Answers2

17

atan2 returns all possible angles because it's not used just for drawing lines! It's used for actual maths as well, where the difference is important. atan, on the other hand, produces results in [-pi/2, +pi/2].

Oliver Charlesworth
  • 267,707
  • 33
  • 569
  • 680
2

One common application of atan2 is converting from cartesian coordinates to polar coordinates. And that it supports all angles is its reason of existance. Else you could just use atan(y/x).

CodesInChaos
  • 106,488
  • 23
  • 218
  • 262