Hello everyone, I'm doing a project with a GPS and I'm stuck on the calculation of the distance between two coordinates, probably because I'm wrong to use the types of data. I need help !
I.E. I have two cordinates as described below:
LatA 43.824254
LngA 10.477824
LatB 43.825185
LngB 10.482122
The formula I have to use is :
= 6372.795477598 * arccos (sen (LatA) * sen (LatB) + cos (LatA) * cos (LatB) * cos (LngA-LngB))
This is on Execel and it works fine, verified through Google Earth (in this example: 360m)
-I know the values must be converted from degrees to radians (radians = degrees * 3,14/180) -
The code in C++ I wrote is:
float LatA = 43.824254;
float LATB = 43.825185;
float LngA = 10.477824;
float LNGB = 10.482122;
Float Dist;
Dist = 6372.795477598 * ACOs (sin (latA * 3.14/180) * sin (LATB * 3.14/180) + cos (lata * 3.14/180) * cos (LATB * 3.14/180) * cos (Lnga * 3.14/180-LNGB * 3.14/180));
Please, first get rid of the following confusions:
Arccos and ACOs are the same. Is it arc cosine?
Sen and sin are the same. Is it sine function?
Lata and latA are the same. Is it latitude A
The following formula misses the balancing parenthses:
The formula I have to use is :
= 6372.795477598 * Arccos (Sen (Lata) * Sen (LATB) + cos (lata) * cos (LATB) * cos (Lnga-LNGB)
Hi,
When you use the two co-ordinates, is one of the co-ordinates the current position of the GPS?
In other words are you trying to calculate the distance from where the GPS is to a set point?
Have you got a GPS and controller working at the moment?
There is a provision in the GPS library for you to get the GPS to calculate the distance for you if you input into a function the set point long and lat.
yes I have a GPS working fine! I would like to give a coordinate and know how far it is the point from actual position.
I use TinyGPS library... i found what you say.. just need to try, thank you
and it seems to return a meaningful value for the coordinates you gave (0.36011km or 360.11m).
I ifdef'd out your coordinates and used some from different ones to correlate with the site and got a very close value (1112.1062km vs their value of 1112.142km.)
Float variables and calculations are good to only 6 decimal digits, which is not enough for accurate lat/lon distance calculations, and doubles are not supported by Arduino.
GPS libraries like NeoGPS get around this by using a number of tricks, such as using long integers to store coordinates in units of degrees10^6 or degrees10^7.
Well they are ;), it's just that on Uno etc they're the same size as floats.
Notes and Warnings
Users who borrow code from other sources that includes double variables may wish to examine the code to see if the implied precision is different from that actually achieved on ATMEGA based Arduinos.
jremington:
Float variables and calculations are good to only 6 decimal digits, which is not enough for accurate lat/lon distance calculations, and doubles are not supported by Arduino.
I have wanted to say that ATSAM3X8E based Arduino DUE Board allows to have a 15-digit accuracy (tested) after the decimal point in the binary64 formatted floating point calculation through the declaration of double x;.