views:

160

answers:

2

Hi,

I am looking for a way to calculate the distance between 2 points on the globe. We've been told to use Haversine, which works fine to calculate the shortest distance between the 2 points.

Now, I'd like to calculate the "long distance" between to points. So suppose you have 2 cities, A in the west and B in the east. I want to know the distance from B to A if I would travel eastwards around the globe and then reach A coming from the west.

I've tried changing a couple of things in the haversine function, but doesn't seem to work.

Anyone know how I can simply do this using small adjustments to the haversine function?

This is what I'm using now:

lat1, lat2, lng1, lng2 are in radians

part1 = sin(lat2) * sin(lat1); part2 = cos(lat2) * cos(lat1) * cos(lng1 - lng2);

distance = 6378.8 * acos(part1 + part2);

The way I see it is that you can draw a circle around the globe between the 2 cities. The long distance the the circumference of that circle minus the short distance. But in contrary of what was replied, the circle's length is not equal to the earth's circumference. This is only the case for 2 points on the equator.

Tnx Jeroen

+1  A: 

The circumference of the earth is approx 40,075KM, work out the short distance and subtract it from that.

Robin Day
Hooray for low-tech.
Jonathan Feinberg
The circumference is different depending on the latitude.
Jeroen
What you say would be correct at the equator though ;)
Jeroen
Agreed, on further thought I think I'm wrong... Interesting problem
Robin Day
On further thinking, the shortest route is perpendicular to the equator and therefore the longest route is the circumference minus this. Whilst there are "other" routes that could be taken, the number is infinite!
Robin Day
Basically what I think I need is the same circle as the one that defines the shortest path, but then around the world.
Jeroen
So basically the shortest long path, if that makes sense. It's got More to do with direction.
Jeroen
A: 

Check out this tutorial on how to find the distance.

http://www.movable-type.co.uk/scripts/latlong.html

Ally

related questions