2

i need to find the distance between two gps location, So i think to do this:

  • lat1(seconds)-lat2(seconds)=lat * 30.7151 == distance latitude in meters =Latm

  • long1(seconds)-long2(seconds)=long *30.9221=== distance longitude in meters=Longm

for overall distance between them = sqr(Latm^2+Longm^2). note: the nodes are in range of 30 meters so i need to deal with seconds cause it is small scale.

H.H
  • 177
  • 3
  • 10

1 Answers1

4

Euclidean distances don't make much sense when calculated from lat/long. Haversine formula is used to calculate distance between lat/long on the surface of the earth surface. If the distance between the two places in question is large please consider using Haversine formula. Some detail and a calculator for Haversine formula can be found at: http://www.movable-type.co.uk/scripts/latlong.html

If the places in question are not far apart, then you can convert the lat/long to UTM and then use the normal formula for Euclidean Distance:

d=sqrt((x1-x2)^2+(y1-y2)^2)
DotPi
  • 779
  • 1
  • 8
  • 24
  • in this link, i didn't know what this function ""atan2"" – H.H Apr 19 '13 at 08:23
  • atan2 is a function which is provided in most programming languages to calculate the arc-tangent between the 2 points; i.e the angle between 2 points. atan2 is special in the sense that it takes into account the signs of the inputs. I do not know whether the atan2 function is provided in TinyOS. If not atan2 can be implemented using normal arctangent function. Details about what the arctangent function is and how it can be implemented using atan can be found in the wikipedia page: http://en.wikipedia.org/wiki/Atan2 . – DotPi Apr 19 '13 at 08:36
  • However, before implementing the atan2 function yourself, I would request you to check the API of TinyOS to see whether atan2 is supported. Generally this function is found in the math library of programming languages. – DotPi Apr 19 '13 at 08:39
  • o, i will check that. if i want to follow this equation =ACOS(SIN(lat1)SIN(lat2)+COS(lat1)COS(lat2)COS(lon2-lon1))6371

    then the (lat,lon) in radian, but also when i use cos or cosd cos for degree cosd for radian

    i am confused if i use long and lat in radian then use the (cos and sin) in radian or degree ?

    – H.H Apr 19 '13 at 08:45
  • Generally one should use radians for calculations related to angles. You can use the normal cos and sin functions as long as you are using radians. – DotPi Apr 19 '13 at 08:50
  • when i use this equation, give lat and long as degree 33.46680, but when i convert it to radian and follow this equation i get 0 as output of acos function !!! this make the distance equal to zero !! – H.H Apr 19 '13 at 12:00
  • Try the calculator in this site...http://www.yourhomenow.com/house/haversine.html. There might be something wrong with either the conversion between degrees to radians or the way you wrote the equation. – DotPi Apr 19 '13 at 13:32
  • i use this site http://www.movable-type.co.uk/scripts/latlong-vincenty.html

    but when i try to do some experiment and adjust two GPS antenna between them 4 meters and try to get the two gps values and get the distance between them i have the distance between them is 27-50 meter !!!

    what do you think from where the problem !

    – H.H Apr 19 '13 at 14:49
  • Are you sure the GPS readings you are getting are accurate? – DotPi Apr 19 '13 at 15:14
  • how to know that, i get the value received from antenna ! – H.H Apr 19 '13 at 15:26
  • check with a location of whose lat/long you already know very accurately. You can get the accurate lat/long from a commercial GPS receiver, then you can check whether your receiver is giving the same result or not. Do this for several locations to be absolutely certain, – DotPi Apr 19 '13 at 15:43
  • i used this uBlox LEA-4A what do you think how much its accuracy ? – H.H Apr 19 '13 at 16:49
  • I have never used it. I am not sure. – DotPi Apr 20 '13 at 03:42