# An Earthy Equation

Discussion in 'SimConnect' started by FlapsOut, 17 Jun 2007.

1. ### FlapsOut

Joined:
29 May 2007
Messages:
75
Country:
Anyone studying Physical Geometrics knows that the Earth, rather than being a bedrock hard globe in the heavens, is more like a water-balloon...constantly expanding and contracting as it rotates.

I would like to know that; If I were to calculate a 'Curve-of-the-Earth' distance calculation from, for instance:

'KIAH' to '13TE'? Would anyone have an argument against this formulae? And, if so? What argument?

In C#, BTW...

double distance = CalculateDistanceByTwoLatLngs(30.6560320034623, -96.5383015573025, 29.959241723995, -95.3403444794987);

private double CalculateDistanceByTwoLatLngs(double Latitude1, double Longitude1, double Latitude2, double Longitude2)
{
double Lat1, Lng1, Lat2, Lng2;

Lat1 = (Latitude1 * 3.141592657) / 180;
Lng1 = (Longitude1 * 3.141592657) / 180;
Lat2 = (Latitude2 * 3.141592657) / 180;
Lng2 = (Longitude2 * 3.141592657) / 180;

double distance = Math.Acos(Math.Sin(Lat1) * Math.Sin(Lat2) + Math.Cos(Lat1) * Math.Cos(Lat2) * Math.Cos(Lng2 - Lng1));

if (distance < 0)
distance += Math.PI;

distance = 3959.0 * distance; // 3959.0 being the 'Average Radius of the Earth in Miles'

return (distance);
}

Then? distance = 86.167549658405591 Miles...er, 86.17 miles.

Flaps

P.S. Please do not answer with, 'Well, FSNav says...' or 'Well, FS Commander says...'

Last edited: 17 Jun 2007
2. ### arnoAdministratorStaff MemberFSDevConf teamResource contributor

Joined:
28 May 2004
Messages:
23,991
Country:
Hi,

The only thing I see right away is that you use an average radius of the earth, while the SDK clearly lists the two radii that FS uses for its earth model. So I think that would make it not 100% accurate.

Here are the figures from the SDK:

But I never needed a formula to calculate the distance between two lat/longs over a long distance (only when using meters from a reference point in flat earth), so I don't know if the actual formula you use is correct.

3. ### rhysa

Joined:
23 Mar 2005
Messages:
42
Country:
If you are going to use a spherical model then why not just use the Haversine method?

Then there is the Vincenty method, which I found here that uses an ellipsoidal model if you want to be very accurate. You can use the WGS84 numbers in this method and so you should get a good match with FSX.

FSX uses the WGS-84 standard, it is mentioned in the terrain SDK I think, but also you will see that arno's numbers match up with the WGS84 standard definition.

I've used Haversine mainly because we only do short distance calculations where the error will be very small, and the results we see in FSX back that up.

Last edited: 18 Jun 2007

Joined:
29 May 2007
Messages:
75
Country:
Thanks

Thanks Guys,