Announcement

Collapse
No announcement yet.

How to calculate the sphere surface distance between two points

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to calculate the sphere surface distance between two points

    Click the mouse, get point(lat1,lon1)and point (lat2,lon2)
    from globe , how to calculate the sphere surface distance between two points?
    The earth is not a standard sphere,

  • #2
    i view the source code globe.jshttps://github.com/NASAWorldWind/Web...globe/Globe.js,
    there are two radius

    /**
    * This globe's equatorial radius.
    * @type {Number}
    * @default 6378137.0 meters
    */
    this.equatorialRadius = 6378137.0;

    /**
    * This globe's polar radius.
    * @type {Number}
    * @default 6356752.3 meters
    */
    this.polarRadius = 6356752.3;

    Comment


    • #3
      The WebWorldWind class Location includes the following functions for calculating distance:

      greatCirlceDistance
      rhumbDistance
      linearDistance

      Each of these functions return the distance as an angle in radians, which then must be multiplied by the radius to get a "surface" distance.

      The methods mentioned above assume a spherical earth.
      Zach
      World Wind Team
      https://github.com/NASAWorldWind

      Comment


      • #4
        Here are a couple of utility functions I wrote for the app I built that do that. Hope they help.

        /*
        * This function returns the distance in meters between two WorldWind.Locations (i.e. between two geographical lat-lon locations)
        * This function uses the great circle method for determining distance and does not consider altitude.
        */
        var DistanceInMetersBetweenTwoLocations = function(location1, location2)
        {
        var radius = 6378137.0; // radius of the world wind globe in meters
        var distanceAsAngle = WorldWind.Location.greatCircleDistance(l ocation1, location2);
        return distanceAsAngle * radius;
        };


        /*
        * This function returns the distance in meters between two WorldWind.Positions (i.e. between two geographical lat-lon-alt positions)
        * This function uses the great circle method for determining horizontal distance then also considers altitude into the distance using the Pythagorean theorem.
        */
        var DistanceInMetersBetweenTwoPositions = function(position1, position2)
        {
        var location1 = Util.LocationFromPosition(position1);
        var location2 = Util.LocationFromPosition(position2);

        var alt1 = position1.altitude;
        var alt2 = position2.altitude;

        //So to include alt first we get the horizontal great circle distance (at the estimated surface of the earth's alt of 6378137)
        var horizontalDistance = DistanceInMetersBetweenTwoLocations(loca tion1, location2);

        //Now we get the distance of the difference in altitude
        var heightDifferenceDistance = Math.abs(alt1-alt2);

        //Now to include the alt distance also between our two positions also we simply use the Pythagorean theorem A^2 + B^2 = C^2
        //Where A is the horizontal great circle distance and B is the distance of the difference in altitude which will result in c the distance between the two positions.
        //A squared plus B squared equals c squared.
        var aSquared = horizontalDistance * horizontalDistance; //Squares our horizontalDistance
        var bSquared = heightDifferenceDistance * heightDifferenceDistance; //Squares our heightDifferenceDistance
        var cSquared = aSquared + bSquared; //Calculates C which is the square of our distance

        var c = Math.sqrt(cSquared); //Extracts C from C Squared which is our distance.

        return c; //Returns the distance in meters between the two positions passed in
        };

        Comment

        Working...
        X