views:

614

answers:

4

How do you draw the curve representing the shortest distance between 2 points on a flat map of the Earth?

Of course, the line would not be a straight line because the Earth is curved. (For example, the shortest distance between 2 airports is curved.)

EDIT: THanks for all the answers guys - sorry I was slow to choose solution :/

+6  A: 

I get this sort of information from the Aviation Formulary.

In this case:

Distance between points

The great circle distance d between two points with coordinates {lat1,lon1} and {lat2,lon2} is given by:

d=acos(sin(lat1)sin(lat2)+cos(lat1)cos(lat2)*cos(lon1-lon2))

A mathematically equivalent formula, which is less subject to rounding error for short distances is:

d=2*asin(sqrt((sin((lat1-lat2)/2))^2 + cos(lat1)cos(lat2)(sin((lon1-lon2)/2))^2))

And

Intermediate points on a great circle

In previous sections we have found intermediate points on a great circle given either the crossing latitude or longitude. Here we find points (lat,lon) a given fraction of the distance (d) between them. Suppose the starting point is (lat1,lon1) and the final point (lat2,lon2) and we want the point a fraction f along the great circle route. f=0 is point 1. f=1 is point 2. The two points cannot be antipodal ( i.e. lat1+lat2=0 and abs(lon1-lon2)=pi) because then the route is undefined. The intermediate latitude and longitude is then given by:

    A=sin((1-f)*d)/sin(d)
    B=sin(f*d)/sin(d)
    x = A*cos(lat1)*cos(lon1) +  B*cos(lat2)*cos(lon2)
    y = A*cos(lat1)*sin(lon1) +  B*cos(lat2)*sin(lon2)
    z = A*sin(lat1)           +  B*sin(lat2)
    lat=atan2(z,sqrt(x^2+y^2))
    lon=atan2(y,x)
Paul Tomblin
Paul, you said, "which is less subject to rounding error for short distances". How short a distance is this good for? I need something that will be accurate for 100M to 1000M distances.
KevinDTimm
@kevin - I was quoting the Aviation Formulary. I have no idea what he considered short, but I always use the "less subject to rounding error" version for my flight planner.
Paul Tomblin
Thanks! The intermediate points on the great cirlce is exactly what I needed. Btw , sorry for not being too clear on the question - my knowlege in this area is currently vague at best.
helloworlder
A: 

Your question is totally dependend on the projection used. (and a projection of course will be used to form a 3D earth to a flat map.)

An easy solution is to use the Mercator projection :

Azimuthality: The Mercator projection's greatest strength is its ability to show the loxodrome between any two points as a straight line. ...

This changed with the introduction of maps based on Mercator's projection. For the first time, sea captains had maps showing loxodromes as straight lines. All that a captain had to do was draw a line connecting his starting and ending points on a Mercator chart, measure the bearing of this line, and then sail that bearing until he reached his destination.

Peter
Downvoted, a straight line on the Mercator projection is a rhumb line (line of constant bearing) not a great circle (shortest route between two points on the surface of a spherical earth).
High Performance Mark
Tx, I have corrected it
Peter
The shortest distance between two points is definetly not depedending on the projection used, it depends only on the points. The shortest distance does exist, even if there is no projection at all.
drhirsch
you want a http://en.wikipedia.org/wiki/Gnomonic_projection for great circles to be straight lines
jk
the distance doesn't depend on the projection but drawing the path does
jk
@rhirsh : that is the bleeding obvious, you better read the question : how do you draw it, totally dependent..
Peter
No, I didn't just google it, I used to navigate freighters.
High Performance Mark
@High Performance Mark : I was only talking about myself, never said anything about you, sorry if that came over wrongly
Peter
Sorry, I was wrong, did read to fast.
drhirsch
+1  A: 

Hi

Off the top of my head I don't know how to program this. However, what you are trying to do is to plot a (segment of a) great circle on a map with a given projection. Try Googling the first and then the second term.

Regards

Mark

High Performance Mark
+2  A: 

To draw the 3D shortest path between two points on Earth's surface onto a 2D map of Earth's surface, you have to know how the 3D surface of Earth was projected onto the 2D map in question. If you know the projection used, you just need to apply it to the 3D shortest path to project it onto the 2D map. If you don't know the exact projection used, but have access to it through some sort of interface (ie. input 3D surface coords -> output 2D map coords), you could sample points along the 3D surface path, generate their corresponding map points through said interface, and then approximate the projected path with line segments/bezier curves/etc. through the projected sample points.

Donnie DeBoer