View previous topic :: View next topic |
Author |
Message |
championx
Joined: 28 Feb 2006 Posts: 151
|
calculating distance from gps coordinates |
Posted: Thu Nov 16, 2017 6:13 pm |
|
|
Hi! do anyone have calculated distance using GPS coordinates?
It uses some complex math functions, do you have any advice to do this?
thanks |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9230 Location: Greensville,Ontario
|
|
Posted: Thu Nov 16, 2017 7:06 pm |
|
|
use integers
do NOT use floating point
search the forum |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1908
|
|
Posted: Thu Nov 16, 2017 7:12 pm |
|
|
https://en.wikipedia.org/wiki/Haversine_formula
Definitely use integers. If you're attempting this in a PIC, your accuracy (gut feeling only) isn't going to be on the order of meters or better. What sort of accuracy do you require? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19524
|
|
Posted: Fri Nov 17, 2017 2:35 am |
|
|
<http://www.ccsinfo.com/forum/viewtopic.php?t=27879&highlight=haversine>
<http://www.ccsinfo.com/forum/viewtopic.php?t=27947&highlight=cordic>
<http://www.ccsinfo.com/forum/viewtopic.php?t=47980&highlight=haversine>
The cordic code _with some added care to handle the quadrants and special cases_, can give great results. |
|
|
championx
Joined: 28 Feb 2006 Posts: 151
|
|
Posted: Wed Aug 04, 2021 1:36 pm |
|
|
Hi! i tested successfully the haversine formula. I get very good results on long distances (more than 5km) but on short distances (less than 100m) i get very big errors... is there a better way to calculate the distance when this is very short?
I will calculate the distance once every few seconds, so, always will be less than 50 meters.
I tried simple Pythagoras formula... but i get unstable results...
Any hint?
thanks! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19524
|
|
Posted: Thu Aug 05, 2021 1:19 am |
|
|
At the end of the day it is all down to how you store the values. and the
arithmetic you use. If you are using a standard 32bit floating point number
to hold the angles, this only gives about 6.5 digits of 'accuracy'. Some values
are held exactly, but others have large errors (depends on how the binary
representation expands for the particular number). At the equator, a
32bit FP number can only represent a point to an average accuracy of about
0.2 kilometer.
The arithmetic formulae for things like sin and cos, are only coded to
give an accuracy of perhaps 5.5 digits. Problem is that the more accurate
you make these, the slower they are, and the more bulky they are. The
standard functions only give accuracy adequate for 99% of typical uses.
What I suggest, is that you change rules. For distances where the delta
between the angles in either direction is more than a degree, you use the
Haversine formula. However when the delta angle is smaller than this
switch to using simple Pythagoras. The error from the curvature of the
Earth over angles this small is tiny, and simple Pythagoras, will over these
distances give a much better result, and do it quicker too.
You will still have the rounding error inherent in the FP format, but
the overall behaviour should be much better. |
|
|
|