PDA

View Full Version : Calculation of the distance between 2 coordinates of GPS in meters



Pimentel
- 26th June 2009, 22:55
Hello,

I have a project using a GPS module in my car e now I want to improve it adding a new option... I want to know if I am near of some known poitns as radars of speeds of the roads then I thought about calculating in the distance between known LA/LON of the current LAT/LON and to test if this value is greater that one determined ray, for example 30 meters.
As I want I covered an area relatively small I I thought about transforming degree, minute and seconds of the coordinates format of my gps ('$GPRMC,151805.812,A,2241.6835,S,04700.3015,W,0.0 0,,131206,,*1F ) in degrees and then to find the difference using the theorem of pitagoras: square shaped root of x^2+y^2, where x is lat1-lat2 and y is long1-long2. I have all datas in arrays (Lat var byte[9]: Lon var byte[10]).
To convert I think it: GRAUs = GRAUS+(MIN/60)+((.mmmm*60)/3600). Finally I multiply the value in degrees of the difference of the 2 coordinates for the value of 111120 meters (ray of the planet in the Equator), to only have an approach value. I also can search the accurate value of a degree in my region!
Somebody can help with some algorithm to only decide this problem using word and byte variables?

Thanks

Pimentel

ScaleRobotics
- 26th June 2009, 23:33
Hello Pimentel,

You can use atan2 to find the angle heading from one lat/lon to another lat/lon coordinate. PicBasic doesn't include that math function, but you can use an assembly include file to perform a cordic equation for atan2. If you do a search on cordic in this forum, you will find one include for PIC16 devices, and one for PIC18 devices. There is also a trick to convert longitude to an adjusted value based on the cosine of current lat. I will explain a little more about this later.

Here is a link explaining how to use the PIC16 trig include file with lat/lon. In it you will find a link for the cordic trig include file thread.

http://www.picbasic.co.uk/forum/showthread.php?p=71216#post71216

-Walter