两个经纬度之间的距离计算


将西经看作负值,东经看作正值,北纬看作负值,南纬看作正值。则纬度的取值范围是 [ − π 2 , π 2 ] [-\frac{\pi}{2}, \frac{\pi}{2}] [2π,2π] , 经度的取值范围为 [ − π , π ] [-\pi, \pi] [π,π]. 当然,正负可以根据个人喜好随意规定,并不会影响最终的计算结果。

1. 经纬度与空间直角坐标系的变换关系

假定地球半径为 R R R , 对于地面上的任意一点,假定其纬度与经度分别为 θ \theta θ, φ \varphi φ, 则转化到三维空间直角坐标系有
{ x = R cos ⁡ θ cos ⁡ φ y = R cos ⁡ θ sin ⁡ φ z = R sin ⁡ θ \left\{\begin{array}{l}x=R \cos \theta \cos \varphi \\ y=R \cos \theta \sin \varphi \\ z=R \sin \theta\end{array}\right. x=Rcosθcosφy=Rcosθsinφz=Rsinθ
在这里插入图片描述

2. 在三维直角坐标系中利用向量内积来计算

在这里插入图片描述

计地心为 O O O , 地面上的 A A A 点的纬度与经度分别为 θ 1 \theta_{1} θ1, φ 1 \varphi_{1} φ1, B B B 点的纬度与经度分别为 θ 2 \theta_{2} θ2, φ 2 \varphi_{2} φ2, 在空间直角坐标系中的坐标分别为 ( x 1 , y 1 , z 1 ) (x_{1}, y_{1}, z_{1}) (x1,y1,z1), ( x 2 , y 2 , z 2 ) (x_{2}, y_{2}, z_{2}) (x2,y2,z2), 则

cos ⁡ ∠ A O B = x 1 x 2 + y 1 y 2 + z 1 z 2 R 2 = cos ⁡ θ 1 cos ⁡ φ 1 cos ⁡ θ 2 cos ⁡ φ 2 + cos ⁡ θ 1 sin ⁡ φ 1 cos ⁡ θ 2 sin ⁡ φ 2 + sin ⁡ θ 1 sin ⁡ θ 2 = sin ⁡ θ 1 sin ⁡ θ 2 + cos ⁡ θ 1 cos ⁡ θ 2 cos ⁡ ( φ 2 − φ 1 ) \begin{aligned} & \cos \angle A O B=\frac{x_1 x_2+y_1 y_2+z_1 z_2}{R^2} \\ & =\cos \theta_1 \cos \varphi_1 \cos \theta_2 \cos \varphi_2+\cos \theta_1 \sin \varphi_1 \cos \theta_2 \sin \varphi_2+\sin \theta_1 \sin \theta_2 \\ & =\sin \theta_1 \sin \theta_2+\cos \theta_1 \cos \theta_2 \cos \left(\varphi_2-\varphi_1\right) \end{aligned} cosAOB=R2x1x2+y1y2+z1z2=cosθ1cosφ1cosθ2cosφ2+cosθ1sinφ1cosθ2sinφ2+sinθ1sinθ2=sinθ1sinθ2+cosθ1cosθ2cos(φ2φ1)

S = R ∠ A O B = R arccos ⁡ ( sin ⁡ θ 1 sin ⁡ θ 2 + cos ⁡ θ 1 cos ⁡ θ 2 cos ⁡ ( φ 2 − φ 1 ) ) S=R \angle A O B=R \arccos \left(\sin \theta_1 \sin \theta_2+\cos \theta_1 \cos \theta_2 \cos \left(\varphi_2-\varphi_1\right)\right) S=RAOB=Rarccos(sinθ1sinθ2+cosθ1cosθ2cos(φ2φ1))

3. 在三维直角坐标系中利用勾股定理来计算

根据勾股定理有
A B = ( x 2 − x 1 ) 2 + ( y 2 − y 1 ) 2 + ( z 2 − z 1 ) 2 = R ( cos ⁡ θ 2 cos ⁡ φ 2 − cos ⁡ θ 1 cos ⁡ φ 1 ) 2 + ( cos ⁡ θ 2 sin ⁡ φ 2 − cos ⁡ θ 1 sin ⁡ φ 1 ) 2 = R 2 − 2 sin ⁡ θ 2 − sin ⁡ θ 1 ) 2 \begin{aligned} & A B=\sqrt{\left(x_2-x_1\right)^2+\left(y_2-y_1\right)^2+\left(z_2-z_1\right)^2} \\ & =R \sqrt{\left(\cos \theta_2 \cos \varphi_2-\cos \theta_1 \cos \varphi_1\right)^2+\left(\cos \theta_2 \sin \varphi_2-\cos \theta_1 \sin \varphi_1\right)^2} \\ & =R \sqrt{\left.2-2 \sin \theta_2-\sin \theta_1\right)^2} \end{aligned} AB=(x2x1)2+(y2y1)2+(z2z1)2 =R(cosθ2cosφ2cosθ1cosφ1)2+(cosθ2sinφ2cosθ1sinφ1)2 =R22sinθ2sinθ1)2
因此
sin ⁡ 2 ∠ A O B 2 = ( A B 2 R ) 2 = 1 − sin ⁡ θ 1 sin ⁡ θ 2 − cos ⁡ θ 1 cos ⁡ θ 2 cos ⁡ ( φ 2 − φ 1 ) 2 cos ⁡ 2 ∠ A O B 2 = 1 − sin ⁡ 2 ∠ A O B 2 = 1 + sin ⁡ θ 1 sin ⁡ θ 2 + cos ⁡ θ 1 cos ⁡ θ 2 cos ⁡ ( φ 2 − φ 1 ) 2 \begin{aligned} & \sin ^2 \frac{\angle A O B}{2}=\left(\frac{A B}{2 R}\right)^2=\frac{1-\sin \theta_1 \sin \theta_2-\cos \theta_1 \cos \theta_2 \cos \left(\varphi_2-\varphi_1\right)}{2} \\ & \cos ^2 \frac{\angle A O B}{2}=1-\sin ^2 \frac{\angle A O B}{2}=\frac{1+\sin \theta_1 \sin \theta_2+\cos \theta_1 \cos \theta_2 \cos \left(\varphi_2-\varphi_1\right)}{2} \end{aligned} sin22AOB=(2RAB)2=21sinθ1sinθ2cosθ1cosθ2cos(φ2φ1)cos22AOB=1sin22AOB=21+sinθ1sinθ2+cosθ1cosθ2cos(φ2φ1)

cos ⁡ ∠ A O B = cos ⁡ 2 ∠ A O B 2 − sin ⁡ 2 ∠ A O B 2 = sin ⁡ θ 1 sin ⁡ θ 2 + cos ⁡ θ 1 cos ⁡ θ 2 cos ⁡ ( φ 2 − φ 1 ) \cos \angle A O B=\cos ^2 \frac{\angle A O B}{2}-\sin ^2 \frac{\angle A O B}{2}=\sin \theta_1 \sin \theta_2+\cos \theta_1 \cos \theta_2 \cos \left(\varphi_2-\varphi_1\right) cosAOB=cos22AOBsin22AOB=sinθ1sinθ2+cosθ1cosθ2cos(φ2φ1)
因此两地距离
{ S = R ∠ A O B = R arccos ⁡ ( sin ⁡ θ 1 sin ⁡ θ 2 + cos ⁡ θ 1 cos ⁡ θ 2 cos ⁡ ( φ 2 − φ 1 ) S = 2 R ∠ A O B 2 = 2 R arcsin ⁡ ( 1 − sin ⁡ θ 1 sin ⁡ θ 2 − cos ⁡ θ 1 cos ⁡ θ 2 cos ⁡ ( φ 2 − φ 1 ) 2 ) S = 2 R ∠ A O B 2 = 2 R arccos ⁡ ( 1 + sin ⁡ θ 1 sin ⁡ θ 2 + cos ⁡ θ 1 cos ⁡ θ 2 cos ⁡ ( φ 2 − φ 1 ) 2 ) \left\{\begin{array}{l} S=R \angle A O B=R \arccos \left(\sin \theta_1 \sin \theta_2+\cos \theta_1 \cos \theta_2 \cos \left(\varphi_2-\varphi_1\right)\right. \\ S=2 R \frac{\angle A O B}{2}=2 R \arcsin \left(\sqrt{\frac{1-\sin \theta_1 \sin \theta_2-\cos \theta_1 \cos \theta_2 \cos \left(\varphi_2-\varphi_1\right)}{2}}\right) \\ S=2 R \frac{\angle A O B}{2}=2 R \arccos \left(\sqrt{\frac{1+\sin \theta_1 \sin \theta_2+\cos \theta_1 \cos \theta_2 \cos \left(\varphi_2-\varphi_1\right)}{2}}\right) \end{array}\right. S=RAOB=Rarccos(sinθ1sinθ2+cosθ1cosθ2cos(φ2φ1)S=2R2AOB=2Rarcsin(21sinθ1sinθ2cosθ1cosθ2cos(φ2φ1) )S=2R2AOB=2Rarccos(21+sinθ1sinθ2+cosθ1cosθ2cos(φ2φ1) )

#4.在等腰梯形里计算
如图,假定 A , B , C , D A,B,C,D A,B,C,D为地球表面上四点, A A A 点的纬度与经度分别为 θ 1 , φ 1 \theta_{1}, \varphi_{1} θ1,φ1, B B B 点的纬度与经度分别为 θ 1 , φ 2 \theta_{1}, \varphi_{2} θ1,φ2 , C C C 点坐标为 θ 2 , φ 2 \theta_{2}, \varphi_{2} θ2,φ2, D D D点坐标为 θ 2 , φ 1 \theta_{2}, \varphi_{1} θ2,φ1 , 则四边形 A B C D ABCD ABCD为等腰梯形。
在这里插入图片描述
现在我们要算的是 A , C A,C A,C两点之间的距离 S S S , 显然
{ A B = 2 R sin ⁡ φ 2 − φ 1 2 cos ⁡ θ 1 A D = B C = 2 R sin ⁡ θ 2 − θ 1 2 C D = 2 R sin ⁡ φ 2 − φ 1 2 cos ⁡ θ 2 \left\{\begin{array}{l} A B=2 R \sin \frac{\varphi_2-\varphi_1}{2} \cos \theta_1 \\ A D=B C=2 R \sin \frac{\theta_2-\theta_1}{2} \\ C D=2 R \sin \frac{\varphi_2-\varphi_1}{2} \cos \theta_2 \end{array}\right. AB=2Rsin2φ2φ1cosθ1AD=BC=2Rsin2θ2θ1CD=2Rsin2φ2φ1cosθ2
由余弦定理在 △ A B C \triangle A B C ABC
A C 2 = A B 2 + B C 2 − 2 A B ⋅ B C cos ⁡ ∠ A B C = 4 R 2 sin ⁡ 2 φ 2 − φ 1 2 cos ⁡ 2 θ 1 + 4 R 2 sin ⁡ 2 θ 2 − θ 1 2 − 8 R 2 sin ⁡ φ 2 − φ 1 2 sin ⁡ θ 2 − θ 1 2 cos ⁡ θ 1 cos ⁡ ∠ A B C \begin{aligned} & A C^2=A B^2+B C^2-2 A B \cdot B C \cos \angle A B C \\ & =4 R^2 \sin ^2 \frac{\varphi_2-\varphi_1}{2} \cos ^2 \theta_1+4 R^2 \sin ^2 \frac{\theta_2-\theta_1}{2}-8 R^2 \sin \frac{\varphi_2-\varphi_1}{2} \sin \frac{\theta_2-\theta_1}{2} \cos \theta_1 \cos \angle A B C \end{aligned} AC2=AB2+BC22ABBCcosABC=4R2sin22φ2φ1cos2θ1+4R2sin22θ2θ18R2sin2φ2φ1sin2θ2θ1cosθ1cosABC
同理,在 △ A C D \triangle A C D ACD
A C 2 = A D 2 + C D 2 − 2 A D ⋅ C D cos ⁡ ∠ A D C = 4 R 2 sin ⁡ 2 φ 2 − φ 1 2 cos ⁡ 2 θ 2 + 4 R 2 sin ⁡ 2 θ 2 − θ 1 2 − 8 R 2 sin ⁡ φ 2 − φ 1 2 sin ⁡ θ 2 − θ 1 2 cos ⁡ θ 2 cos ⁡ ∠ A D C = 4 R 2 sin ⁡ 2 φ 2 − φ 1 2 cos ⁡ 2 θ 2 + 4 R 2 sin ⁡ 2 θ 2 − θ 1 2 + 8 R 2 sin ⁡ φ 2 − φ 1 2 sin ⁡ θ 2 − θ 1 2 cos ⁡ θ 2 cos ⁡ ∠ A B C \begin{aligned} & A C^2=A D^2+C D^2-2 A D \cdot C D \cos \angle A D C \\ & =4 R^2 \sin ^2 \frac{\varphi_2-\varphi_1}{2} \cos ^2 \theta_2+4 R^2 \sin ^2 \frac{\theta_2-\theta_1}{2}-8 R^2 \sin \frac{\varphi_2-\varphi_1}{2} \sin \frac{\theta_2-\theta_1}{2} \cos \theta_2 \cos \angle A D C \\ & =4 R^2 \sin ^2 \frac{\varphi_2-\varphi_1}{2} \cos ^2 \theta_2+4 R^2 \sin ^2 \frac{\theta_2-\theta_1}{2}+8 R^2 \sin \frac{\varphi_2-\varphi_1}{2} \sin \frac{\theta_2-\theta_1}{2} \cos \theta_2 \cos \angle A B C \end{aligned} AC2=AD2+CD22ADCDcosADC=4R2sin22φ2φ1cos2θ2+4R2sin22θ2θ18R2sin2φ2φ1sin2θ2θ1cosθ2cosADC=4R2sin22φ2φ1cos2θ2+4R2sin22θ2θ1+8R2sin2φ2φ1sin2θ2θ1cosθ2cosABC
联立以上两式消去 cos ⁡ ∠ A B C \cos \angle A B C cosABC可得
A C 2 = 4 R 2 sin ⁡ 2 φ 2 − φ 1 2 cos ⁡ θ 1 cos ⁡ θ 2 + 4 R 2 sin ⁡ 2 θ 2 − θ 1 2 A C^2=4 R^2 \sin ^2 \frac{\varphi_2-\varphi_1}{2} \cos \theta_1 \cos \theta_2+4 R^2 \sin ^2 \frac{\theta_2-\theta_1}{2} AC2=4R2sin22φ2φ1cosθ1cosθ2+4R2sin22θ2θ1

sin ⁡ 2 ∠ A O C 2 = A C 2 4 R 2 = sin ⁡ 2 φ 2 − φ 1 2 cos ⁡ θ 1 cos ⁡ θ 2 + sin ⁡ 2 θ 2 − θ 1 2 cos ⁡ 2 ∠ A O C 2 = 1 − sin ⁡ 2 ∠ A O C 2 = cos ⁡ 2 θ 2 − θ 1 2 − sin ⁡ 2 φ 2 − φ 1 2 cos ⁡ θ 1 cos ⁡ θ 2 \begin{aligned} & \sin ^2 \frac{\angle A O C}{2}=\frac{A C^2}{4 R^2}=\sin ^2 \frac{\varphi_2-\varphi_1}{2} \cos \theta_1 \cos \theta_2+\sin ^2 \frac{\theta_2-\theta_1}{2} \\ & \cos ^2 \frac{\angle A O C}{2}=1-\sin ^2 \frac{\angle A O C}{2}=\cos ^2 \frac{\theta_2-\theta_1}{2}-\sin ^2 \frac{\varphi_2-\varphi_1}{2} \cos \theta_1 \cos \theta_2 \end{aligned} sin22AOC=4R2AC2=sin22φ2φ1cosθ1cosθ2+sin22θ2θ1cos22AOC=1sin22AOC=cos22θ2θ1sin22φ2φ1cosθ1cosθ2

cos ⁡ ∠ A O C = cos ⁡ 2 ∠ A O C 2 − sin ⁡ 2 ∠ A O C 2 = sin ⁡ θ 1 sin ⁡ θ 2 + cos ⁡ θ 1 cos ⁡ θ 2 cos ⁡ ( φ 2 − φ 1 ) \cos \angle A O C=\cos ^2 \frac{\angle A O C}{2}-\sin ^2 \frac{\angle A O C}{2}=\sin \theta_1 \sin \theta_2+\cos \theta_1 \cos \theta_2 \cos \left(\varphi_2-\varphi_1\right) cosAOC=cos22AOCsin22AOC=sinθ1sinθ2+cosθ1cosθ2cos(φ2φ1)
与第一种方法得出相同的结果。因此同样有
S = R ∠ A O C = R arccos ⁡ ( sin ⁡ θ 1 sin ⁡ θ 2 + cos ⁡ θ 1 cos ⁡ θ 2 cos ⁡ ( φ 2 − φ 1 ) S = 2 R ∠ A O C 2 = 2 R arcsin ⁡ ( sin ⁡ 2 φ 2 − φ 1 2 cos ⁡ θ 1 cos ⁡ θ 2 + sin ⁡ 2 θ 2 − θ 1 2 ) S = 2 R ∠ A O C 2 = 2 R arccos ⁡ ( cos ⁡ 2 θ 2 − θ 1 2 − sin ⁡ 2 φ 2 − φ 1 2 cos ⁡ θ 1 cos ⁡ θ 2 ) \begin{aligned} & S=R \angle A O C=R \arccos \left(\sin \theta_1 \sin \theta_2+\cos \theta_1 \cos \theta_2 \cos \left(\varphi_2-\varphi_1\right)\right. \\ & S=2 R \frac{\angle A O C}{2}=2 R \arcsin \left(\sqrt{\sin ^2 \frac{\varphi_2-\varphi_1}{2} \cos \theta_1 \cos \theta_2+\sin ^2 \frac{\theta_2-\theta_1}{2}}\right) \\ & S=2 R \frac{\angle A O C}{2}=2 R \arccos \left(\sqrt{\cos ^2 \frac{\theta_2-\theta_1}{2}-\sin ^2 \frac{\varphi_2-\varphi_1}{2} \cos \theta_1 \cos \theta_2}\right) \end{aligned} S=RAOC=Rarccos(sinθ1sinθ2+cosθ1cosθ2cos(φ2φ1)S=2R2AOC=2Rarcsin(sin22φ2φ1cosθ1cosθ2+sin22θ2θ1 )S=2R2AOC=2Rarccos(cos22θ2θ1sin22φ2φ1cosθ1cosθ2 )

4. 距离公式的总结

综合上述推导过程,得出以下5个正确结果
{ S = R arccos ⁡ ( sin ⁡ θ 1 sin ⁡ θ 2 + cos ⁡ θ 1 cos ⁡ θ 2 cos ⁡ ( φ 2 − φ 1 ) S = 2 R arcsin ⁡ ( 1 − sin ⁡ θ 1 sin ⁡ θ 2 − cos ⁡ θ 1 cos ⁡ θ 2 cos ⁡ ( φ 2 − φ 1 ) 2 ) S = 2 R arccos ⁡ ( 1 + sin ⁡ θ 1 sin ⁡ θ 2 + cos ⁡ θ 1 cos ⁡ θ 2 cos ⁡ ( φ 2 − φ 1 ) 2 ) S = 2 R arcsin ⁡ ( sin ⁡ 2 φ 2 − φ 1 2 cos ⁡ θ 1 cos ⁡ θ 2 + sin ⁡ 2 θ 2 − θ 1 2 ) S = 2 R arccos ⁡ ( cos ⁡ 2 θ 2 − θ 1 2 − sin ⁡ 2 φ 2 − φ 1 2 cos ⁡ θ 1 cos ⁡ θ 2 ) \left\{\begin{array}{l} S=R \arccos \left(\sin \theta_1 \sin \theta_2+\cos \theta_1 \cos \theta_2 \cos \left(\varphi_2-\varphi_1\right)\right. \\ S=2 R \arcsin \left(\sqrt{\frac{1-\sin \theta_1 \sin \theta_2-\cos \theta_1 \cos \theta_2 \cos \left(\varphi_2-\varphi_1\right)}{2}}\right) \\ S=2 R \arccos \left(\sqrt{\frac{1+\sin \theta_1 \sin \theta_2+\cos \theta_1 \cos \theta_2 \cos \left(\varphi_2-\varphi_1\right)}{2}}\right) \\ S=2 R \arcsin \left(\sqrt{\sin ^2 \frac{\varphi_2-\varphi_1}{2} \cos \theta_1 \cos \theta_2+\sin ^2 \frac{\theta_2-\theta_1}{2}}\right) \\ S=2 R \arccos \left(\sqrt{\cos ^2 \frac{\theta_2-\theta_1}{2}-\sin ^2 \frac{\varphi_2-\varphi_1}{2} \cos \theta_1 \cos \theta_2}\right) \end{array}\right. S=Rarccos(sinθ1sinθ2+cosθ1cosθ2cos(φ2φ1)S=2Rarcsin(21sinθ1sinθ2cosθ1cosθ2cos(φ2φ1) )S=2Rarccos(21+sinθ1sinθ2+cosθ1cosθ2cos(φ2φ1) )S=2Rarcsin(sin22φ2φ1cosθ1cosθ2+sin22θ2θ1 )S=2Rarccos(cos22θ2θ1sin22φ2φ1cosθ1cosθ2 )
根据上述推导过程,很容易知晓这 5 个结果是相等的,读者也可以自行验证。

参考

请问如何计算两个经纬度之间的距离?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值