CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

calculating distance from gps coordinates

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
championx



Joined: 28 Feb 2006
Posts: 151

View user's profile Send private message

calculating distance from gps coordinates
PostPosted: Thu Nov 16, 2017 6:13 pm     Reply with quote

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: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Nov 16, 2017 7:06 pm     Reply with quote

use integers
do NOT use floating point
search the forum
newguy



Joined: 24 Jun 2004
Posts: 1899

View user's profile Send private message

PostPosted: Thu Nov 16, 2017 7:12 pm     Reply with quote

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: 19195

View user's profile Send private message

PostPosted: Fri Nov 17, 2017 2:35 am     Reply with quote

<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

View user's profile Send private message

PostPosted: Wed Aug 04, 2021 1:36 pm     Reply with quote

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: 19195

View user's profile Send private message

PostPosted: Thu Aug 05, 2021 1:19 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group