1

My question is about Haversine formula as arcsin x = arctan x/(sqrt(1-x^2), therefore the formula should have atan x and not atan2 x when we convert the formula from arcsin to arctan.

θ = 2 arcsin(sqrt(a)) = 2 arctan(sqrt(a)/(sqrt(1-a)))

But in most of the previews answers has an extra 2 after atan. Can anyone explain it to me please. Thanks

Hasan
  • 21
  • 1
  • Isn't this question more appropriate for http://math.stackexchange.com/ ? – kkaosninja Jan 22 '17 at 15:26
  • google "atan vs atan2"; or look here: http://stackoverflow.com/questions/283406/what-is-the-difference-between-atan-and-atan2-in-c – Rich L Jan 22 '17 at 16:39
  • Why do you call that the "Haversine formula"? There is no [haversine](https://en.wikipedia.org/wiki/Versine#hav) in it, and [another formula](https://en.wikipedia.org/wiki/Haversine_formula) is called that. – Rory Daulton Jan 22 '17 at 18:29

1 Answers1

3

atan(x) is the same as atan2(x,1). atan2(y,x) is the angle of the point (x,y), while atan(y/x) is the angle of the line through the origin and (x,y).

The only inverse trigonometric function present as FPU on x86 CPU/FPUinstruction is FPATAN which implements atan2. Thus also asin(x) is implemented as atan2(x,sqrt(1-x*x)), acos(x) as atan2(sqrt(1-x*x),x).

Lutz Lehmann
  • 25,219
  • 2
  • 22
  • 51