Talk:Haversine formula
From Wikipedia, the free encyclopedia
Contents |
Why atan2?
In the formula for d, you can use either arcsin or arctangent:
- d = 2 R asin(√h) = 2 R atan2(√h, √(1−h))
The Census Bureau FAQ recommends using the atan2 function instead of the asin function, but I have to confess that I can't see why.
The stated explanation is that the asin function requires "bulletproofing" in order to check that √h doesn't exceed unity, while "no bulletproofing is needed for an inverse tangent", but this makes no sense to me: in the atan2 version, you still need to check that h doesn't exceed 1 or or the square root will fail.
(On the other hand, if your trig and square root functions operate on complex numbers, neither case will fail—you'll just get a small imaginary part, which you can ignore, if h slightly exceeds 1.)
Moreover, I just did a numerical check using the GNU C library math functions (which are usually pretty good) in double precision (~16 decimal places) on a Pentium (IV), comparing to an arbitrary-precision (50-decimal places) calculation, and both the asin and atan versions are equally (in)accurate. For h = 1-1e-13, both versions give an error of about 3.16e-7 compared to the correct result of 1.5707963267948966192313216916397514420985846996876 for d/2R.
So, I'm going to delete the recommendation to use arctangent, as a bit of "folk numerical analysis" that maybe was true for somebody's pocket calculator years ago but doesn't seem to have any relation to reality now. Please, feel free to correct me if I'm missing something.
—Steven G. Johnson 03:43, Apr 12, 2004 (UTC)
What's the formula?
In one part of the article it is claimed that:
- haversin(θ) = sin2(θ / 2)
While later on the article says:
- the use of detailed printed haversine charts saved navigators from squaring sines and halving the result
which would imply that:
- haversin(θ) = sin2(θ) / 2
So do you square an angle's sine and then halve the result, or halve the angle and then square its sine? --Delirium 08:51, Apr 12, 2004 (UTC)
- The first formula is correct (see also the versine article for the etymology...the haversine is half the versine). I didn't write that sentence in the article, so I can only speculate that the author of that sentence meant the halving of the argument, not the result, or perhaps the doubling of the result. I've modified the article to clarify. —Steven G. Johnson 17:46, Apr 12, 2004 (UTC)
-
- Apologies; that was truly idiotic of me. I also was the originator of the whole "haversin(d/R) = h, where h=etc." wording, which I see has been changed. I don't blame you; it was cumbersome. But I thought the replacement was rather confusing; so I've proposed yet another version. I know "right-hand-side" sounds amateurish: but I really think the goal should be to be as intelligible to all readers, even at the cost of amateurishness. Doops 05:31, 14 Apr 2004 (UTC) P.S. I also see that my 'rammify' has been altered, which I kinda expected because it's old-fashioned and eccentric: but it really is a perfectly sensible use of the word. Look it up. :)
-
-
- I assume you mean 'ramify'. I'm familiar with the word, and ramify small errors would be appropriate to describe the errors branching into many different computations, but is not really the right connotation for magnifying them in a single computation. —Steven G. Johnson
-
Why solve for d?
OK, I've got a question: why solve for d at all? In order to calculate the distance directly by the equation given, you will have to take the square root of a number which is likely to be near one; then caculate the arcsine of that. Wouldn't it be much, much easier to have, along with your detailed, printed table of haversines, a detailed, printed table of archaversines? Doops 05:39, 14 Apr 2004 (UTC)
- Of course. A detailed printed table for the haversine is a detailed printed table for the inverse haversine...you just look up in the other column. As the article says, this saved navigators from squaring sines, computing square roots, etc. —Steven G. Johnson 05:56, Apr 14, 2004 (UTC)
-
- >As the article says, this saved navigators from squaring sines, computing square roots, etc.
- Exactly! It was that phrase of yours which led me to ask the question! :) Doops 06:14, 14 Apr 2004 (UTC)
RHS vs. LHS
I'm sorry to keep bringing this up; but I am really not happy with the language Let h denote haversin(d/R), given from above. &c. &c.
Since I'm obviously not the expert here, and since I don't want to be annoying, I'm not going to change it back again; but I really have to say that this phrasing seems counterintuitive to me. Although doubtless its a perfectly defensible statement mathematically, it does seem to be saying, in effect, "let h = the LHS" when what we want to say is "let h = the RHS". Now obviously RHS = LHS, so this perhaps shouldn't matter; but I'm worried that somebody might plug h=haversin(d/R) into the formulae on the next line, getting the perfectly pointless result d=dR/R.
- It's not at all circular, since LHS = RHS. Because the equation relating the two was one line before the defnition of h, I find it hard to believe that the reader would not realize that they have to use the RHS to apply the equation. —Steven G. Johnson
-
- Yes; but why? I'm sure people can figure it out; perhaps the con- argument is no big deal; but what's the pro- argument? I simply don't see the point in doing things in a non-intuitive way.
-
-
- The subtly-weird statement, to me, is to explicitly define h as one "side" or the other of an equation where both sides are equal—h is just a number, not a symbolic expression. Given that number, and knowing the relevant relation h = haversin(d/R), you then want to find d. This is algebra, not a computer programming language; "=" is equality, not assignment. —Steven G. Johnson 00:03, Apr 15, 2004 (UTC)
-
-
-
-
- Gosh, I have so many comments I don't know where to begin!
- first of all, Stevenj, you haven't answered my question: what is the argument in favor of the current version?
- secondly, perhaps you're right that explicitly defining h as the RHS is weird. But I think (see below) that the text as it stands right now implicitly "defines" "h" as the LHS.
- right now, the text reads "let h denote sin2(θ/2)." "Denote" seems pretty much like assignment to me! That is to say, when I hear the word 'denote,' I imagine a little label pointing at the expression with the letter h written on it. Not a mathematical definition, but a mental one.
- And there is a very real difference between the two sides of the equation here: the RHS (as you point out above) is simply a number, which we can calculate based on observable data; but the LHS isn't! Or at least we don't think of it that way — if we thought of it that way, then we'd have a useless tautology!
- But I guess we could treat both sides as 'just a number'; I guess we could go whole hog and, after giving the equation, begin the paragraph by saying: "Call this quantity h. By solving the eqation above we can find the distance d in terms of h and R (the known radius of the earth), etc. etc." We'd refer to the equation as a value, then proceed in the next line to manipulate it again like an active equation; but at least this would make the definition of h RHS/LHS-neutral.
- Anyway, sorry for worrying at this so much. I'm not trying to be obnoxious! I just really believe in making things as straightforward as possible. Doops 03:14, 15 Apr 2004 (UTC)
-
-
The only reason (correct me if I'm wrong) for using h at all is to make the formula less messy-looking; if we were willing to have a long, confusing formula we could just write (for the 3rd large-font equation) d=R archaversin (haversin Δ&phi etc. etc.) And perhaps we should just go with that! But if we really do want to use h for the sake of simplicity, I think things will simply be much more simple if we get people thinking of h as another name for the RHS. The present language may mean that to some people; but not, I think, to all.
(Also, regarding the second version of the solved-for-d equation: don't you think we should make more explicit how it was derived? I think the mention (now deleted) that the def'n of haversine was applied before the arcsine taken was useful. Isn't it better to show than to tell?)
- At a certain point, adding verbiage to belabor the obvious makes things less clear. —Steven G. Johnson 19:45, Apr 14, 2004 (UTC)
-
- That's certainly true (see my new comment below). Doops 03:14, 15 Apr 2004 (UTC)
Again, I'm not an expert: which means (on the one hand) that I should be humble in altering the article; but on the other, that I might have useful suggestions regarding how it will sound to the layman. Doops 18:35, 14 Apr 2004 (UTC)
Possible rearrangement
Hi. I've put up a possible rearrangement of the whole article at Talk:Haversine_formula/Alt
Some points about it:
- The main goal was to arrange the article so that the novice outsider, upon clicking to it, could get a quick summary of the haversine formula as quickly and painlessly as possible.
- All discussions about the technical aspects and rationale are moved to the second section, the first paragraph of which is intended for the general reader. The rest of the section (which I haven't presumed to write) would be more technical in nature, and could perhaps be in smaller type to make this distinction clear.
- I've left the remainder of the article unchanged.
Comments? If you like this ordering, please work on that second section (beyond the first paragraph) so that there's a logical progression! Thanks— Doops 03:14, 15 Apr 2004 (UTC)