12

I'm working on adding geofences to a mobile application. I know the proper way of calculating distance between two points on a sphere is using the great-circle or Haversine formula. I don't know if using those formulas are needed for relatively small scale applications. This leads to my question.

At what point does the distance given by a great-circle calculation diverge significantly from a planar calculation?


  • For the purposes of this discussion assume greater than 5% error is significant.

  • The geofence is simply a center point and a radius. If the point is within the radius, by distance, it is considered within the boundaries of the fence.

  • I am not sure if it matters, but I'm just worried about circular geofences at this time with a user defined radius between 50 and 200 meters.

Erik
  • 309
  • 3
  • 11
  • 4
    It's not the radius of the circle that matters so much as the number of vertices used to define it. http://gis.stackexchange.com/questions/175393/circle-area-calculation-in-qgis-is-inaccurate/175394#175394 – Vince Feb 16 '16 at 23:10
  • @Vince I'm confused about "vertices" for a circular geofence. There wouldn't be vertices persay to define it. Just a center point and a radius. If the distance from the center point is less than or equal to the radius it would be within the fence. – Erik Feb 16 '16 at 23:15
  • 2
    No, in the real world, circles are represented as polygons. The resulting figure can be indexed, improving the performance of the 'inside' test over a full table scan distance calculation (avoiding a square root calculation). – Vince Feb 17 '16 at 00:15
  • @Vince Regardless of how programmers optimize/implement the inside problem there should be a mathematical solution that describes the divergence between a planar solution and an Earth sized sphere. All that being said I very well might not understand the point you're driving at. If you can post an answer that explains the problem in more domain appropriate terms and gives a superior solution that I can understand I'll certainly up-vote it and quite possibly accept it. As it stands I'm incapable of understanding how circles are always polygons meaningfully answers my question. – Erik Feb 17 '16 at 00:40
  • If we're talking about the distance between two points, we could put them on a circle instead of a sphere, which reduces the complexity of the problem. Is you question then basically: at what point does the chord length deviate from the arc length by 5% given two points on a circle? If that's the case, the answer is about 6993 km, which is way more than 200 m. I would put this and the explanation as an answer, but I want to make sure I fully understand your question. – user55937 Mar 01 '16 at 17:35
  • @user55937 It has been a long time since I took geometry, but that doesn't feel like it would accurately reflect the question. My mental picture could be wrong, but I visualize the problem like a sphere with planar circle sitting on top like a hat with the contact point being the origin location. Then there would be another point on the sphere. A great circle calculation would give the accurate distance to that other point. A planar circle calculation would give a false distance to that other point. Your plan feels wrong because the planar calculation (cord) is inside the earth not above. – Erik Mar 01 '16 at 17:54
  • The answer I was thinking of and the answer you're looking for are related by a cos(theta) (interior angle between the two points), so they're going to be virtually the same for the very small angles you'd be considering. But you're right that I did misunderstand your question. – user55937 Mar 01 '16 at 18:10
  • 3
    I have answered versions of this question in many places on this site, including http://gis.stackexchange.com/questions/25494 (discussing the error in using a sphere instead of an ellipsoid), http://gis.stackexchange.com/questions/7293 (errors in a Mercator projection), http://gis.stackexchange.com/questions/1351 (discussion of Equidistant projections), http://gis.stackexchange.com/questions/155828 (a direct answer to this question in terms of local Cartesian coordinates), http://gis.stackexchange.com/questions/5068 (calculating distance distortions in any projection), – whuber Mar 01 '16 at 19:45
  • 1
    (continued) http://gis.stackexchange.com/questions/107992 (another analysis of errors in local distance calculations), and http://gis.stackexchange.com/questions/58653 (another direct answer involving an analysis of the entire sphere). – whuber Mar 01 '16 at 19:46

1 Answers1

2

whuber gave a wonderful answer that addresses the central folly of this idea. While he doesn't say this directly most people, like me, initially overlook two interrelated factors.

  1. Longitude converges at the poles. That means that the distance between 0o longitude and 1o longitude is different when measuring along the equator and the 80th parallel.

  2. Planar coordinate systems rely on a constant rate of change in both the x and y directions no matter where you are located. In a graph moving one step to the right is always the same distance irregardless of whether I'm at the origin or 80 steps above/below the origin.

As you can see the longitude breaks this assumption and therefore it will produce variably poor results. It is not merely a question of x distance traveled equates to y error, because the scale/magnitude varies depending on where the points are on the globe.

As you can see even though it is appealing to view the GPS coordinate system as a planar graph with a bounding box, the planar graph analogy doesn't work because of how longitude is structured. As such a methodology that would work on a planar graph is wholly inappropriate for a problem utilizing latitude and longitude.

To play on an analogy that whuber made in his answer, treating GPS coordinates like points on a planar graph is like trying to square the circle. Many people have tried, but they were inevitably disappointed.

Erik
  • 309
  • 3
  • 11