Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Algorithms
  4. Distance between two GPS points.

Distance between two GPS points.

Scheduled Pinned Locked Moved Algorithms
question
13 Posts 9 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C chandu004

    hai all, is it possible to find the distance in meters between the two points if i have, their longitude, latitude and height. iam aware that, the distance between two adjacent graticules is not standatd in all the places on the earth. but, based on the height, can we do any thing? thanks for your views.

    D Offline
    D Offline
    DQNOK
    wrote on last edited by
    #4

    Are you talking points that are close, or anywhere on Earth; that is, are you wanting to take into account the curvature of the Earth? Another question: Are you talking about the great-circle distance (around the curvature of the Earth), or a straight line (which would have to tunnel thru the Earth if distances are very far)? David

    CPalliniC 1 Reply Last reply
    0
    • C chandu004

      we can do this, but iam not sure weather this applies through out the globe. any way, thanks for your response.

      Y Offline
      Y Offline
      yuneiv
      wrote on last edited by
      #5

      I can, 100% sure. Just show me what and how GPS bases on, I'll find a way.

      1 Reply Last reply
      0
      • D DQNOK

        Are you talking points that are close, or anywhere on Earth; that is, are you wanting to take into account the curvature of the Earth? Another question: Are you talking about the great-circle distance (around the curvature of the Earth), or a straight line (which would have to tunnel thru the Earth if distances are very far)? David

        CPalliniC Offline
        CPalliniC Offline
        CPallini
        wrote on last edited by
        #6

        Ha has a neutrino gun! :-D

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

        In testa che avete, signor di Ceprano?

        E 1 Reply Last reply
        0
        • CPalliniC CPallini

          Ha has a neutrino gun! :-D

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

          E Offline
          E Offline
          El Corazon
          wrote on last edited by
          #7

          CPallini wrote:

          Ha has a neutrino gun!

          dagnabbit! I want one!!!! :-D

          _________________________ Asu no koto o ieba, tenjo de nezumi ga warau. Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)

          1 Reply Last reply
          0
          • C chandu004

            hai all, is it possible to find the distance in meters between the two points if i have, their longitude, latitude and height. iam aware that, the distance between two adjacent graticules is not standatd in all the places on the earth. but, based on the height, can we do any thing? thanks for your views.

            E Offline
            E Offline
            El Corazon
            wrote on last edited by
            #8

            chandu004 wrote:

            is it possible to find the distance in meters between the two points if i have, their longitude, latitude and height.

            The short answer: Yes. The long answer: you need to deal with great-circle (geodesic solution) calculations. See: http://mathworld.wolfram.com/GreatCircle.html[^] There is also an iterative solution that is often used for boat/air travel. Obviously continuously changing your heading to provide the absolute shortest route to the meter is difficult. So you create waypoints travel to them, change heading and travel to the next, etc., until you reach your destination. This has become easier with computers because a computer auto-pilot will auto-navigate to many more waypoints with micro changes in heading to keep a shorter path. But with ocean travel that is somewhat more difficult. The question becomes how accurate do you need it, and what is the purpose of the answer. The piece-wise iterative approach would be: surfacedistance(from: lat, lon, alt; to: lat, long, alt) { distance= ECEFdistance(ecef(to),ecef(from)); // choose your desired approximation level for accuracy if (distance<1000) return distance; // else recurse and use piecewise approximation ecef_mid=ecef_to*0.5+ecef_from*0.5; spher_mid=togeodetic(ecef_mid); spher_mid.alt=from.alt*0.5+to.alt*0.5; return surfacedistance(from,spher_mid)+surfacedistance(spher_mid,to); } or something similar (that is off the top of my head, google piecewise approximation of geodesic distances. The idea is that you can sum a series of vector distances in local space and the more accurate your division, the more accurate the answer. You can choose speed over accuracy at any point by changing the approximation distance change between mid-point division and vector-distance. The bad news is, if you set the value too low, it is a heavy recursion level and you are better off calculating it directly. There are times in implimentation you may want to do either for other reasons related to use of the answer.

            _________________________ Asu no koto o ieba, tenjo de nezumi ga warau. Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)

            1 Reply Last reply
            0
            • C chandu004

              hai all, is it possible to find the distance in meters between the two points if i have, their longitude, latitude and height. iam aware that, the distance between two adjacent graticules is not standatd in all the places on the earth. but, based on the height, can we do any thing? thanks for your views.

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #9

              chandu004 wrote:

              is it possible to find the distance in meters between the two points if i have, their longitude, latitude and height.

              Like these: http://mathforum.org/library/drmath/view/51720.html http://jan.ucc.nau.edu/~cvm/latlongdist.html http://mathforum.org/library/drmath/view/51711.html http://www.movable-type.co.uk/scripts/latlong-vincenty.html http://mathforum.org/library/drmath/view/54680.html http://www.freevbcode.com/ShowCode.asp?ID=5532 http://mathforum.org/library/drmath/view/51717.html http://www.meridianworlddata.com/Distance-Calculation.asp http://mathforum.org/library/drmath/view/51722.html http://www.csgnetwork.com/longlatdistance.html http://mathforum.org/library/drmath/view/54941.html http://www.csgnetwork.com/lldistcalc.html http://mathforum.org/library/drmath/view/54680.html


              "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

              "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

              C 1 Reply Last reply
              0
              • D David Crow

                chandu004 wrote:

                is it possible to find the distance in meters between the two points if i have, their longitude, latitude and height.

                Like these: http://mathforum.org/library/drmath/view/51720.html http://jan.ucc.nau.edu/~cvm/latlongdist.html http://mathforum.org/library/drmath/view/51711.html http://www.movable-type.co.uk/scripts/latlong-vincenty.html http://mathforum.org/library/drmath/view/54680.html http://www.freevbcode.com/ShowCode.asp?ID=5532 http://mathforum.org/library/drmath/view/51717.html http://www.meridianworlddata.com/Distance-Calculation.asp http://mathforum.org/library/drmath/view/51722.html http://www.csgnetwork.com/longlatdistance.html http://mathforum.org/library/drmath/view/54941.html http://www.csgnetwork.com/lldistcalc.html http://mathforum.org/library/drmath/view/54680.html


                "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                C Offline
                C Offline
                chandu004
                wrote on last edited by
                #10

                thanks a lot david, one of the above links helped me to understand many interesting points. and the logic worked for some of hte examples, so far i have tested.

                E 1 Reply Last reply
                0
                • C chandu004

                  hai all, is it possible to find the distance in meters between the two points if i have, their longitude, latitude and height. iam aware that, the distance between two adjacent graticules is not standatd in all the places on the earth. but, based on the height, can we do any thing? thanks for your views.

                  R Offline
                  R Offline
                  Reagan Conservative
                  wrote on last edited by
                  #11

                  You probably know that the "standard distance" for 1 nautical mile is 6076.115 feet. And that 1 degree of latitude is 60 Nautical miles (NM). There is no "standard" for longitude since it is wider at the equator and they all conjoin at the poles to zero distance. I think there is a formula for determining the length of 1 degree of longitude based on the latitude where the longitude is taken, but don't know it offhand. If you are somewhere in the range of 30 to 60 degrees latitude, the "standard distance" formula will get you close to the correct distance between two points.

                  John P.

                  1 Reply Last reply
                  0
                  • C chandu004

                    thanks a lot david, one of the above links helped me to understand many interesting points. and the logic worked for some of hte examples, so far i have tested.

                    E Offline
                    E Offline
                    El Corazon
                    wrote on last edited by
                    #12

                    chandu004 wrote:

                    and the logic worked for some of hte examples, so far i have tested.

                    the logic should work quite well. I haven't gone through most of the links, but I checked a few of them. I am not sure what you need the answer for, but it would be wise to clarify that your answer is for a spherical Earth not an ellipsoidal model. At least the ones I followed so far assume a spherical earth. This is a decent approximation, but again, it depends on what you are trying to do. No answer will be exactly right because even an ellipsoidal model is an approximate surface. The true surface is mapped in elevation points to the geoid.

                    _________________________ Asu no koto o ieba, tenjo de nezumi ga warau. Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)

                    1 Reply Last reply
                    0
                    • C chandu004

                      hai all, is it possible to find the distance in meters between the two points if i have, their longitude, latitude and height. iam aware that, the distance between two adjacent graticules is not standatd in all the places on the earth. but, based on the height, can we do any thing? thanks for your views.

                      R Offline
                      R Offline
                      RichardM1
                      wrote on last edited by
                      #13

                      the easiest way to do it (assuming spherical earth)is to convert the lat-lon values into X-Y-Z values. The center of the earth is (0,0,0), the intersection of the prime meridian and the equator is (R,0,0) lat 0, lon +90 is (0,R,0), the north pole is (0,0,R) the south pole is (0,0,-R) where R = radius of earth to go from lat lon to x y z is: x = R * Cos(lon) * Cos(lat) y = R * Sin(Lon) * Cos(lat) z = R * Sin(lat) You do that for point 1 and point 2, then determine the distance between them (straight line) x' = x2-x1 y' = y2-y1 z' = z2-z1 d = sqrt((x'*x')+(y'*y')+(z'*z')) One half of the angle from point 1 to point 2 is a = ArcSin(d/2R) to get the great circle distance take this angle (in radians), double it to get the actual angle, them multiply if by the radius of the earth D = 2 * a * R where D is the distance you are looking for.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups