calculate distance between two points

mrkrishnanmrkrishnan Global Mapper UserPosts: 29
edited July 2010 in SDK
hai
i want to calculate the distance between two points which are in Latitude, longitude and altitude format. I saw an API in Global mapper GM_calcDistance - which will convert the value only with respect to latitude and longitude, But i want to calculate with respect to altitude also.

Example: Position 1: Lat: 31 Long:35 Altitude:1000
Position 1: Lat: 32 Long:37 Altitude:5000

Is there any API to calculate like this?
If not how can i calculate?



Regards
Radhakrishnan

Comments

  • global_mapperglobal_mapper Administrator Posts: 17,238
    edited July 2010
    While there's no API to calculate the 3D distance, just calculate the 2D distanced with GM_CalcDistance, then just use the Pythagorean theorem to add the altitude. Your 3D distance can be calculated as:

    alt_diff = end_altitude - start_altitude; // 5000 - 1000 in your case
    3d_dist = sqrt( 2d_dist * 2d_dist + alt_diff * alt_diff );

    Be sure to check that your altitude units and distance units are the same before doing this.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • mrkrishnanmrkrishnan Global Mapper User Posts: 29
    edited July 2010
    thanks mike. i am using that formula only. i just want to conform weather any API is available or not?
  • global_mapperglobal_mapper Administrator Posts: 17,238
    edited July 2010
    No, there is not any API available for 3D distance calculation.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • baotd86baotd86 Posts: 2
    I have made an example distance calculate but it always returns 0, 
    this is my script:

    double aDist;
    GlobalMapperDLL.GM_CalcDistance(159.09988, 200.99877, 176.09987, 225.9887, 201, out aDist);

    Plz, show tell what wrong i did.
    many thanks
  • aaroncaaronc Posts: 25Trusted User
    The call for GM_CalcDistance is:

    public static extern GM_Error_t32 GM_CalcDistance
                (
                double      aFromX,     // IN: start X/longitude coordinate
                double      aFromY,     // IN: start Y/latitude coordinate
                double      aToX,       // IN: stop X/longitude coordinate
                double      aToY,       // IN: stop Y/latitude coordinate
                byte        aLatLon,    // IN: TRUE - coordinates are lat/lon, FALSE - coordinates are in the current projection?
                out double aDist       // OUT: distance in meters between the points
                );

    I'm not sure what your coordinates should be but you are passing 201 as a byte which is effectively a bool value to select whether you are lat/lon or the current coordinate system.  That means that it is saying true for using lat/lon but your x and y are greater than lat/lon should be.
Sign In or Register to comment.