Python计算两大圆相交点

0 投票
2 回答
2704 浏览
提问于 2025-04-17 16:39

我正在尝试计算两个大圆的交点(以度数表示的纬度和经度),每个大圆都是由圆上的两个点定义的。我一直在按照这里提到的方法进行操作。可是我得到的答案不对,我的代码如下,不知道有没有人能帮我找出问题所在?

import numpy as np
from numpy import cross
from math import cos, sin, atan2, asin, asinh

################################################
#### Intersection of two great circles.
# Points on great circle 1.
glat1 = 54.8639587
glon1 = -8.177818

glat2 = 52.65297082
glon2 = -10.78064876

# Points on great circle 2.
cglat1 = 51.5641564
cglon1 = -9.2754284

cglat2 = 53.35422063
cglon2 = -12.5767799

# 1. Put in polar coords.

x1 = cos(glat1) * sin(glon1)
y1 = cos(glat1) * cos(glon1)
z1 = sin(glat1)

x2 = cos(glat2) * sin(glon2)
y2 = cos(glat2) * cos(glon2)
z2 = sin(glat2)


cx1 = cos(cglat1) * sin(cglon1)
cy1 = cos(cglat1) * cos(cglon1)
cz1 = sin(cglat1)

cx2 = cos(cglat2) * sin(cglon2)
cy2 = cos(cglat2) * cos(cglon2)
cz2 = sin(cglat2)


# 2. Get normal to planes containing great circles.
#    It's the cross product of vector to each point from the origin.

N1 = cross([x1, y1, z1], [x2, y2, z2])
N2 = cross([cx1, cy1, cz1], [cx2, cy2, cz2])


# 3. Find line of intersection between two planes.
#    It is normal to the poles of each plane.

L = cross(N1, N2)


# 4. Find intersection points.

X1 = L / abs(L)
X2 = -X1


ilat = asin(X1[2]) * 180./np.pi
ilon = atan2(X1[1], X1[0]) * 180./np.pi

我还要提到,这个计算是在地球表面进行的(假设地球是个球体)。

2 个回答

0

还有一个需要修正的地方,就是在x和y维度的“lon”前面要加上cos和sin:

x = cos(lat) * cos(lon)
y = cos(lat) * sin(lon)
z = sin(lat)

这是因为最初从角度转换到球面坐标系统时,使用的是极坐标/方位角,而这些和经纬度的角度是不一样的(你可以在维基百科上查一下 https://en.wikipedia.org/wiki/Spherical_coordinate_system)。

1

上面评论中DSM的解决方案,你的角度是用度数表示的,而sin和cos函数是需要用弧度来计算的。

另外,下面这行代码

X1 = L / abs(L)

应该改成:

X1 = L / np.sqrt(L[0]**2 + L[1]**2 + L[2]**2) 

撰写回答