[Thread Prev][Thread Next][Index]

Re: closest distance



The following script will find the distance between two points
on the earth using the law of cosines.

For example, if the script is called great-circle-distance.jnlb,
find the distance between Seattle (47.55N, 122.33W) and Tokyo
(35.75N, 139.5E):

yes? go great-circle-distance.jnlb 47.55 `360-122.33` 35.75 139.5
 !-> go great-circle-distance.jnlb 47.55 237.67 35.75 139.5
7707.6 km

Billy K

--------------------------------------------------------------------
\can mode verify
! find the great circle distance between 2 points using the law of cosines
! 4 input arguments specify the (decimal) latitudes/longitudes of the points
! arg1=latitude 1
! arg2=longitude 1 (pos E)
! arg3=latitude 2
! arg4=longitude 2 (pos (E)

let pd=4*atan(1)/180 
let rearth=6371.2   ! radius of the earth in km

! latitude must start from N pole (textbook law of cosines)
let lat1=90-$1
let lat2=90-$3

! convert spherical to Cartesian coordinates
let x1=sin(pd*lat1)*cos(pd*$2)
let y1=sin(pd*lat1)*sin(pd*$2)
let z1=cos(pd*lat1)
let x2=sin(pd*lat2)*cos(pd*$4)
let y2=sin(pd*lat2)*sin(pd*$4)
let z2=cos(pd*lat2)

let d1=(((x1 - x2)^2) + ((y1 - y2)^2)) + ((z1 - z2)^2)
let angle=acos(1-d1/2)		! angular distance between the points
let distance=rearth*angle	! distance on the sphere

say `distance` km
set mode verify

--------------------------------------------------------------------
> Date: Wed, 5 Jan 2005 20:48:59 +0900 (JST)
> From: Namba Takaya <takayanamba7@yahoo.co.jp>
> Subject: closest distance
> To: ferret_users@noaa.gov
> 
> Dear Sir
> 
> Are there any ways(functions) to measure the closest
> distance of two different points with longtide and
> latitude information by ferret?
> 
> Best Regards,
> 
> Takaya Namba
> 
> __________________________________
> Do You Yahoo!?
> Upgrade Your Life
> http://bb.yahoo.co.jp/
> 


[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement