4

Task

Calculate the distance d in meters between a query-point q and a polygon P.

The query-point q is defined as tuple (latitudeq, longitudeq), the polygon P as ordered list of tuples [(latitude1, longitude1), ..., (latituden, longituden)].

Problem

I can't handle latitude and longitude as if they were x- and y-coordinates of a plane as this leads to huge errors if the polygon is not small and not near (0, 0).

Tools

I know how to calculate the distance between two points given each points latitude and longitude. I do also know how to calculate the distance between a point and a great circle. But for this task I'd need to know how to calculate the distance dist(q, 1—2) between a point q and and part of a great-circle 1—2. The distance of q would be simply min(dist(q, ab)) ∀ ab in P.

Question

Can you provide me a formula how to calculate the distance between a query-point q defined by a tuple (latitudeq, longitudeq) and a great-circle-arc defined by pair of latitude-longitude-tuples [(latitude1, longitude1),(latitude2, longitude2)]?

Example

Query-point *q* and polygon *P* defined by eight points). What is the distance *d* in meters?

user2033412
  • 1,950
  • 2
  • 27
  • 47
  • Can you post your formula for distance between two points in latitude / longitude? There are several ways you might express it / normalize it, so it would help who answers the question to see how you are thinking about it – Chris Beck Aug 31 '16 at 18:32
  • 1
    I believe what you search is the so called **cross track distance**, meaning the distance of point q to the nearest point of a great circle a--b path, [This page from movable type](http://www.movable-type.co.uk/scripts/latlong.html) may be of interest for you. – makadev Aug 31 '16 at 18:34

1 Answers1

0

If you had code to compute the distance between one point x and a geodesic line segment s, you could repeat this for each edge of your geodesic polygon.

Let s=(a,b). s is an arc of a great circle. Rotate the sphere so that s lies on the equator, and x follows along with the sphere rotation. Then the latitude of x essentially tells you the distance to s: It is either the distance from x to a, or x to b, or, if x lies in the sector above/below s, it is a simple factor (2 π r) times the latitude.

Joseph O'Rourke
  • 4,346
  • 16
  • 25