DPlot Forum Index DPlot
http://www.dplot.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Distance Between Points Command

 
Post new topic   Reply to topic    DPlot Forum Index -> Suggestions/Questions
View previous topic :: View next topic  
Author Message
alleyjo



Joined: 28 Jan 2013
Posts: 7

PostPosted: Tue Feb 26, 2013 9:37 am    Post subject: Distance Between Points Command Reply with quote

Do you have a command that can programatically report the distance between two geodectic points, i.e., longitudes and latitudes, in an XY plot?
Back to top
View user's profile Send private message
DPlotAdmin
Site Admin


Joined: 24 Jun 2003
Posts: 2310
Location: Vicksburg, Mississippi

PostPosted: Tue Feb 26, 2013 12:31 pm    Post subject: Reply with quote

No, but there isn't that much to it and you can incorporate this into your own code easily enough. In FORTRAN:
Code:
c
c==============================================================================
c
      real*8 function r_earth(lat)
      implicit none
      real*8   lat    ! latitude in radians

      real*8   a, b
      parameter (a=3963.191)    ! equatorial radius in miles
      parameter (b=3949.903)    ! polar radius in miles
      real*8   r

      r = sqrt( ( (a*a*cos(lat))**2 + (b*b*sin(lat))**2 ) /
     1          ( (a*cos(lat))**2   + (b*sin(lat))**2   )
     2        )
      r_earth = r
      return
      end
c
c==============================================================================
c
      real*8 function latlontodistance(lat1, lon1, lat2, lon2)
      implicit none
      real*8 lat1, lon1, lat2, lon2   ! latitude and longitude in degrees

      real*8 lat1r, lat2r, lon1r, lon2r
      real*8 d, pi
      real*8 dlon, dlat, a, c

      real*8 r_earth
      external r_earth

      if((lat1 .eq. lat2) .and. (lon1 .eq. lon2)) then
        d = 0.0
      else
        pi = 4.0*atan(1.D0)
        lat1r = lat1 * pi/1.8D2
        lon1r = lon1 * pi/1.8D2
        lat2r = lat2 * pi/1.8D2
        lon2r = lon2 * pi/1.8D2

c       Haversine formula:

        dlon = lon2r - lon1r
        dlat = lat2r - lat1r

        a = (sin(dlat/2))**2 +
     1      (cos(lat1r) * cos(lat2r) * (sin(dlon/2))**2)
        c = 2 * atan2(sqrt(a), sqrt(1.D0-a))
        d = r_earth(lat1r) * c
      endif
      latlontodistance = d
      return
      end


latlontodistance returns the distance between 2 points in miles, given the input latitude and longitude of 2 points in degrees.
_________________
Visualize Your Data
support@dplot.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    DPlot Forum Index -> Suggestions/Questions All times are GMT - 5 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