| 
 
	积分3625贡献 精华在线时间 小时注册时间2014-10-21最后登录1970-1-1 
 | 
 
| 
;该程序首先需要2个位置的经纬度坐标,以其中一个为原点,求另一个点相对此点的距离和方位角
x
登录后查看更多精彩内容~您需要 登录 才可以下载或查看,没有帐号?立即注册 
  ;代码开始:
 pro lonlat_to_Polar
 
 
 ;坐标原点,以天安门为例
 core=[116.403849,39.915467]
 ;研究的位置,以北大为例
 point=[116.316979,39.998817]
 
 
 ;二者矢量差
 dif=point-core
 
 
 ;把矢量差的元素做成单位一,后面给距离加正负号
 ;这里dif也可能有0,需要注意
 if(dif[0] ne 0)then dif[0]=dif[0]/abs(dif[0])
 if(dif[1] ne 0)then dif[1]=dif[1]/abs(dif[1])
 if(dif[0] eq 0)then dif[0]=0
 if(dif[1] eq 0)then dif[1]=0
 
 
 ;经向标量距离
 lon_distance=map_2points(core[0],core[1],point[0],core[1],/meters)
 ;纬向标量距离
 lat_distance=map_2points(core[0],core[1],core[0],point[1],/meters)
 ;距离矢量x,第一个元素是经向距离,第一个元素是纬向距离,西负东正,南负北正
 x=[lon_distance,lat_distance]*dif
 
 
 
 
 ;求距离:
 r=sqrt((x[0])^2.0+(x[1])^2.0)
 ;求方位角:
 theta=acos(x[1]/r)
 if(x[0] lt 0)then theta=!dpi*2-acos(x[1]/r)
 ;输出距离和方位角(角度制):
 print,r,theta/!pi*180.0
 
 
 end
 
 
 输出:
 11878.814       321.36267
 北大在天安门北约12公里,方位角321度
 
 
 | 
 |