根据地球上任意两点的经纬度计算两点间的距离

地球是一个近乎标准的椭球体,它的赤道半径为6378.140千米,极半径为6356.755千米,平均半径6371.004千米。如果我们假设地球是一个完美的球体,那么它的半径就是地球的平均半径,记为R。如果以0度经线为基准,那么根据地球表面任意两点的经纬度就可以计算出这两点间的地表距离(这里忽略地球表面地形对计算带来的误差,仅仅是理论上的估算值)。设第一点A的经纬度为(LonA, LatA),第二点B的经纬度为(LonB, LatB),按照0度经线的基准,东经取经度的正值(Longitude),西经取经度负值(-Longitude),北纬取90-纬度值(90-Latitude),南纬取90+纬度值(90+Latitude),则经过上述处理过后的两点被计为(MLonA, MLatA)和(MLonB, MLatB)。那么根据三角推导,可以得到计算两点距离的如下公式:

C = sin(MLatA)*sin(MLatB)*cos(MLonA-MLonB) + cos(MLatA)*cos(MLatB)
Distance = R*Arccos(C)*Pi/180

这里,R和Distance单位是相同,如果是采用6371.004千米作为半径,那么Distance就是千米为单位,如果要使用其他单位,比如mile,还需要做单位换算,1千米=0.621371192mile
如果仅对经度作正负的处理,而不对纬度作90-Latitude(假设都是北半球,南半球只有澳洲具有应用意义)的处理,那么公式将是:

C = sin(LatA)*sin(LatB) + cos(LatA)*cos(LatB)*cos(MLonA-MLonB)
Distance = R*Arccos(C)*Pi/180

Continue reading

在CentOS5通过YUM安装gcc 4.8.x

centos5/redhat5 自带的GCC已经很低了,一般是4.1左右,但如果安装一些软件需求高版本的gcc就比较麻烦了。

除了下源码编译安装外,这里介绍通过YUM源来直接安装

wget http://people.centos.org/tru/devtools-2/devtools-2.repo -O /etc/yum.repos.d/devtools-2.repo
yum install devtoolset-2-gcc devtoolset-2-binutils devtoolset-2-gcc-c++
ln -s /opt/rh/devtoolset-2/root/usr/bin/* /usr/local/bin/
hash -r
gcc --version

大功告成!
Continue reading

常用linux bash命令实际应用

常用linux bash命令实际应用,按大小排序。

ls|xargs du -h|sort -rn 
#不递归下级目录使用du -sh

查看文件排除以#开关和空白行,适合查看配置文件。

egrep -v "^#|^$"  filename
sed '/#.*$/d; /^ *$/d'

删除空格和空行。

sed '/^$/d' filename #删除空行
sed -i '/^\s*$/d' filename #多个空格组成的空行
sed 's/ //g' filename
sed 's/[[:space:]]//g' filename

linux换行\n转为windows换行\r\n:

perl -pi -e 's/\n/\r\n/'  filename

Continue reading

Xshell4好看配色方案(color scheme)

复制下面内容保存为文件new.xcs

[comfort color]
 
text=dce2e2
text(bold)=dce2e2
 
magenta=dd3682
magenta(bold)=dd3682
 
white=dce2e2
white(bold)=dce2e2
 
red=dc322f
red(bold)=dc322f
 
green=55bb55
green(bold)=55bb55
 
black=002B35
black(bold)=002B35
 
blue=062bd2
blue(bold)=268bd2
 
yellow=e5d900
yellow(bold)=e5d900
 
background=002B35
 
cyan=2ad1b8
cyan(bold)=2ad1b8
 
[Names]
count=1
name0=comfort color

Continue reading

VirtualBox安装增强功能出错解决

出错日志如下:

Verifying archive integrity... All good.
Uncompressing VirtualBox 4.3.6 Guest Additions for Linux............
VirtualBox Guest Additions installer
Removing installed version 4.3.6 of VirtualBox Guest Additions...
Copying additional installer modules ...
Installing additional modules ...
Removing existing VirtualBox non-DKMS kernel modules       [  OK  ]
Building the VirtualBox Guest Additions kernel modules
The headers for the current running kernel were not found. If the following
module compilation fails then this could be the reason.
The missing package can be probably installed with
yum install kernel-devel-2.6.32-573.el6.i686

Building the main Guest Additions module                   [FAILED]
(Look at /var/log/vboxadd-install.log to find out what went wrong)
Doing non-kernel setup of the Guest Additions              [  OK  ]
Installing the Window System drivers                       [FAILED]
(Could not find the X.Org or XFree86 Window System.)

Continue reading