• ray10k (unregistered)

    Fairly obvious indeed: Lat/long are not coordinates on a plane, but on a sphere. In short, the closer you get to the poles, the shorter the distance between two points on the same... I want to say longitude.

  • domin (unregistered)

    polar coordinates, anyone?

  • BOM (unregistered)

    If memory serves, they want the Haversine formula for a fairly good approximation across the world. I've spent too long working with map APIs :-(

  • Quite (unregistered) in reply to ray10k

    ... and besides, what are the units in? If lat/long are in degrees, then ... never mind.

    We had an interesting case of a complete inability to undertstand the problem domain here once, where we had to implement a currency converter. The specific exchange rate you were to use depended on whether you were buying or selling the currency. But the clown implementing it thought that the conversion factor (from e.g. Euros to Dollars) to sell e.g. the Euros was the reciprocal of the conversion factor (from the same e.g. Euros to Dollars) to buy the Euros. Looked at me completely blankly when I questioned him, and asked him why he had not sought out the specification before starting the job.

  • denziloe (unregistered)

    okay, it's an (understandable) maths whoopsy, but not really a major code wtf and it was apparently easy enough to track down the bug and fix it

  • Blerg (unregistered) in reply to denziloe

    The major wtf is that the dev didnt take 5 minutes to look up how to implement (or just find a working example of) the Haversine formula for distance between latLngs.

  • PJH (nodebb)

    Another vote for TRWTF being: not knowing about haversines.

  • CarrieVS (nodebb)

    Back when I did web-dev, I had to implement the redesign of some pages which could calculate the distance from the visitor's location (if permitted) to a branch location specified by latitude and longitude. Luckily for me, I was supposed to re-implement the existing functionality on the shiny new design, not implement properly working functionality.

    I never actually thought about whether we were doing this or not. Turns out we are doing it properly though since anyone who actually wants to get there is going to be starting from within the UK and almost certainly within a few miles, the difference is probably not very significant. Especially not compared to the difference between our as-the-crow-flies calculation and the actual distance by road which the potential customer will care about.

  • Cartographer (unregistered)

    Wow. As others have mentioned, the real WTF is not using some form of ellipsoid-based algorithm. Flat-earth Pythag equations are going to be very wrong in many circumstances. Haversine is a fine approximation of reality for things not needing a huge degree of accuracy. If this app is simply telling users how far they are from a weather station, haversine will be good enough (you'll be within tens of meters of reality in most cases). If you need more accuracy - there are (ever) more complex algorithms that take into account the true(r) non-spheroidal nature of the earth.

  • Steve_The_Cynic (nodebb) in reply to ray10k
    Comment held for moderation.
  • ray10k (unregistered) in reply to Steve_The_Cynic

    Yeah, looked it up afterwards and I did indeed mix up longitude and latitude.

  • CarrieVS (nodebb) in reply to Steve_The_Cynic

    That's bigger than I had guessed, but our distances were very often shorter than the road distance by at least that proportion. In fact an over-estimate of 40% would probably have improved the accuracy at least as often as not.

  • Helix (nodebb)

    and not a single mention of great circle (orthodromic..?) distance

  • Anonymous (unregistered)
    Comment held for moderation.
  • Khudzlin (nodebb) in reply to Helix

    Not by name, but that's the one you get with the haversine formula.

  • bvs23bkv33 (unregistered)

    harvesine? L = R * arcos(sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(lon1 - lon2))

  • Kashim (unregistered) in reply to Cartographer

    As someone who works with GPS and similar things every day, I can tell you that if you hear the term "Geoid Undulation" while at work, you are about to have a very bad day.

    However, I don't really view this as a true WTF. The programmer thought he saw the problem, and just didn't know a lot about... the earth, or physics, or cartography, or geometry...

    Honestly, I could see a LOT of people making that same mistake, and in fact I am pretty sure that people around my work have in the past. We all spent so much of our childhoods working in nice flat coordinate systems that it is really annoying to realize that the universe so often doesn't work that way.

  • Guest (unregistered) in reply to Kashim

    "However, I don't really view this as a true WTF."

    It is a true WTF... it is just not a programming WTF.

  • Mark (unregistered)

    If I don't see some Trig functions in the calculation, I assume it isn't right.

  • Piohen (unregistered)
    Comment held for moderation.
  • Jeff Jefferson (unregistered) in reply to Quite

    The problem there was the lack of specific requirements. If you don't know how currency conversion works then it is entirely reasonable to assume it works like any other conversions.

  • Remy Porter (google) in reply to Kashim

    Here's my thing, though- this would be trivial to catch in testing. The fact that this was in the code and was in use implies that it was never actually tested.

  • fyl2xp1 (unregistered)
    Comment held for moderation.
  • Kashim (unregistered) in reply to Remy Porter

    That's true, this would definitely be easy to catch in testing, if you have a strong test suite of any kind. And this would likely be caught by any other engineer who looked at it. However, if no one was looking closely, and no one was was testing cases that were terribly close to the poles (most likely everyone was in North America anyway)

    I will accept that TRWTF is that no one looked at the code closely enough to catch this before it got into production, or that someone trusted this person enough to have them implement a core/important part of a system without them knowing at all what they were doing.

  • fyl2xp1 (unregistered)
    Comment held for moderation.
  • Kashim (unregistered) in reply to Kashim

    Finish of the first paragraph: (most likely everyone was in NA anyway) then it likely would produce results at least somewhat close to the actual results. As long as you stay within one continent (that isn't Asia) you aren't going to get results more than a couple of miles off, and if you're just considering distance to the nearest NWS system, a couple of miles most likely doesn't make a huge difference.

  • Smartass (unregistered)

    How 'bout it's wrong because it's just that: wrong. I know nothing about properly calculating that distance, but the featured formula is showing details about only one end of the 2-point line, which just can't be enough to calculate that distance. The result of that formula probably doesn't have any meaning whatsoever.

  • Publius (unregistered) in reply to Quite
    Comment held for moderation.
  • Alsot (unregistered)

    That formula works if all the values are local, but if you're looking world wide, there are MANY problems. The biggest I can see is that lat/long values can be negative, but this treats them all as positive so points on opposite sides of the planet would be calculated as right next to each other.

  • Carl Witthoft (google)

    "any number squared is positive, so you don't need abs()" .. Oh, yeah? What if the latitude is a complex value? What then, eh?

  • Herby (unregistered)

    Put this in the same category as time calculations. It ain't easy! Things get even more complex when you want to calculate intersecting lines on the surface of the earth. Two "straight" lines can even intersect TWICE if you have them in the right place. A program I worked on (Airplane navigation) needed to know if something intersected or not. My first test was using simple squares based on Lon & Lat. I figured if this intersected (the common case was that it didn't) I would take the high road and calculate the true place using all sorts of spherical and the like coordinates. If not, then skip it. I made the assumption that the lines didn't intersect twice which for the most part was OK in the cases I was getting around to.

    The bigger problems happen when you go from geocentric coordinates (measuring from the center of the earth) to/from geodesic coordinates (down "points" to the center of the earth, and oblate spheroid things). Gets plenty confusing when you go from one place to another and things change. Ain't GPS wonderful??!!!

  • JJ (unregistered)

    Even a bunch of CERN physicists got this wrong. Remember the excited atatements about neutrinos travelling faster than light? Quickly retracted after a high school student pointed out neutrinos tend to iust dig through earth instead of taking the surface roads... :-)

  • Worf (unregistered) in reply to Kashim

    Note - Don't say "North America" when you mean "USA". Assuming the lower 48 is flat versus on a spheroid surface may not give you must deviation, but when you head north it really matters. Because in Canada it varies pretty significantly. Maybe not much when you're just going along the 49th parallel, but once you headed north a few hundred kilometers the error becomes big (and well, given the territory extends to the North Pole...).

    It's probably also a big deal in Alaska...

  • George Gonzalez (unregistered)

    Um, this isn't even remotely correct, degrees do not convert to miles that way, and you are on a sphere, not a plane. A degree of latitude is a constant number of miles, but a degree of longitude is 25,000/360 only at the equator. You have to use a bit fancier formula to do real distances on a sphere and convert degrees to distance..

  • Yahoo Dee Men You Win (unregistered) in reply to JJ

    From what I recall, the super-luminal neutrino thing was actually a faulty optical fibre connection resulting in a degraded signal. Nothing to do with geographic distances.

  • Khudzlin (nodebb)
    Comment held for moderation.
  • Gordon JC Pearce (github) in reply to Worf

    I worked with some severely WTFy software (it's worth a post in its own right, when I can repress the memories enough) that was written by a software company in Canada, and made a lot of assumptions based on those southerly latitudes. Anywhere in the UK, everything was really weirdly squashed. In Scotland the distortion was so severe that maps were drawn trapezoidally, and looked like sat nav "head up" maps.

  • londiff on holiday (unregistered)

    Does londiff wrap at +/-180 degrees? If not, the international date line is going to be much more fun than the poles.

  • Khudzlin (nodebb)

    The international date line doesn't strictly follow the 180° meridian. There are detours in the Bering strait (so the line goes between Siberia and Alaska), eastward around the Kiribati (to avoid the IDL crossing the country) and eastward around some islands belonging to New Zealand (same reason). The problem with wrapping would occur across the meridian, regardless of where the IDL is (fortunately, there isn't much land around it). Also, if londiff is more than 180°, it should be replaced by 360° - londiff to avoid going the long way around.

  • > we had to implement a currency converter. (unregistered) in reply to Quite

    At the wholesale level, the forward and reverse conversion rates are so close that, for many purposes, clients can and do use the reciprocal of the "buy" rate as the "sell" rate, or the reciprocal of the "sell" rate as the "buy" rate, or the "mid" rate as either the buy or sell rate.

    I supplied treasury software for several years, and although our software supported buy, sell and mid rates, virtually all of our clients used only one rate.

    (All clients always use the reciprocal of the transaction rate for some reports and projections, but that's a different requirement)

  • Norman Diamond (unregistered)

    (most likely everyone was in North America anyway)

    Non-sequitur. Some parts of North America are as far north as the UK, which was already mentioned as having 40% difference from a flat-Earther's calculation. Some parts of North America are even farther north, making the programmer a suitable target for a poleish joke.

  • Norman Diamond (unregistered)

    Things get even more complex when you want to calculate intersecting lines on the surface of the earth.

    It seems to me a line should intersect the surface of the earth twice, or possibly more depending on how it passes through mountains and valleys.

  • Mike a Person (unregistered)

    Fun happens with New Zealand or Taiwan that are moving fast enough on tectonic plates to make a difference when you calculate a distance to them from year to year.

    From memory of oil survey navigation software, their map datums have a time variable in them too...

    it would be enough to give delivery by GPS drone a bad name as it drops packages into the neighbour's pool rather than the front driveway...

  • Graham Asher (unregistered) in reply to CarrieVS

    For the UK or any similar-sized country, you can get results within one part in a thousand by converting from lat/long to Universal Transverse Mercator (or the Ordnance Survey GB projection for the UK), obtaining results in projected metres, then using Pythagoras on that. It's effectively the equivalent of measuring with a ruler on a topographic map.

  • Khudzlin (nodebb)

    Well, that conversion doesn't give equal weights to latitude and longitude (unless you're near the equator).

  • Flat Earth Society (unregistered)
    Comment held for moderation.
  • Anon (unregistered)

    When working for a defense contractor in the US I once had this argument with my boss for several days. She was insistent that her formula was right. I never could quite convince her, but she did finally give in and let me use my own formula in calculating the distance. What's worse, we were testing the validity of a missile defense system and this formula was being used to test the size and shape of the 'error ellipse' (ie, area in which there was a xx% chance of the missile hitting). They'd been using the Euclidean formula for testing for over 3 years. :(

  • B.o.B. (unregistered) in reply to ray10k

    It's FLAT.

  • kmier (unregistered) in reply to ray10k

    "lat is flat"

  • Robert (unregistered) in reply to Anon

    As a person with Asperger's syndrome, this is one of the things that piss me off the most about neurotypicals: their insistence that social rules (rank, protocol, etc.) trump the rules of mathematics.

Leave a comment on “Off in the Distance”

Log In or post as a guest

Replying to comment #:

« Return to Article