1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

An Earthy Equation

Discussion in 'SimConnect' started by FlapsOut, 17/6/07.

  1. FlapsOut

    FlapsOut

    Joined:
    29/5/07
    Messages:
    75
    Country:
    us-texas
    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...' :eek:
    Last edited: 17/6/07
  2. arno

    arno Administrator Staff Member FSDevConf team Resource contributor

    Joined:
    28/5/04
    Messages:
    21,304
    Country:
    netherlands
    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

    rhysa

    Joined:
    23/3/05
    Messages:
    42
    Country:
    australia
    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/6/07
  4. FlapsOut

    FlapsOut

    Joined:
    29/5/07
    Messages:
    75
    Country:
    us-texas
    Thanks

    Thanks Guys,

    Two great answers!

    I'm going to add that info and those formulas to my handy-dandy Flight Sim Library! :)

    Flaps

Share This Page