calculate distance between two points
mrkrishnan
Global Mapper User
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
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

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 
thanks mike. i am using that formula only. i just want to conform weather any API is available or not?

No, there is not any API available for 3D distance calculation.
Thanks,
Mike
Global Mapper Support
support@globalmapper.com 
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 
The call for GM_CalcDistance is:public static extern GM_Error_t32 GM_CalcDistance(double aFromX, // IN: start X/longitude coordinatedouble aFromY, // IN: start Y/latitude coordinatedouble aToX, // IN: stop X/longitude coordinatedouble aToY, // IN: stop Y/latitude coordinatebyte 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.
Categories
 12.7K All Categories
 5.6K Features Discussion
 342 Downloading Imagery
 1.3K Elevation Data
 380 Georeferencing Imagery Discussion
 627 GM Script Language
 52 User Scripts
 113 GPS Features
 412 Projection Questions
 818 Raster Data
 1.3K Vector Data
 6.5K Support
 176 Announcement and News
 907 Bug Report
 558 SDK
 1.2K Suggestion Box
 3.7K Technical Support
 561 Other Discussion
 129 GIS Data Sources
 27 Global Mapper Showcase
 232 How I use Global Mapper
 107 Global Mapper Forum Website