[英]Python calculate point of intersection of two great circles
I am trying to calculate the point of intersection (lat and lon in degrees) of two great circles that are each defined by two points on the circle.我正在尝试计算两个大圆的交点(以度为单位的纬度和经度),每个大圆都由圆上的两个点定义。 I have been trying to follow method outlined here .
我一直在尝试遵循此处概述的方法。 But the answer I get is incorrect, my code is below does anyone see where I went wrong?
但是我得到的答案不正确,我的代码在下面有没有人看到我哪里出错了?
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
I should also mention this is on the Earth's surface (assuming a sphere).我还应该提到这是在地球表面(假设是一个球体)。
Solution from DSM in comments above, your angles are in degrees while sin and cos expect radians.上面评论中来自 DSM 的解决方案,您的角度以度为单位,而 sin 和 cos 期望弧度。 Also the line
还有线
X1 = L / abs(L)
should be,应该,
X1 = L / np.sqrt(L[0]**2 + L[1]**2 + L[2]**2)
One more correction that needs to be done is to change cos/sin before "lon" in x and y dimensions:需要做的另一项修正是在 x 和 y 维度中更改“lon”之前的 cos/sin:
x = cos(lat) * cos(lon)
y = cos(lat) * sin(lon)
z = sin(lat)
This is because original conversion from angle to spherical system is done using polar/azimuthal sphere angles and they are not the same as lat/lon angles (wiki it https://en.wikipedia.org/wiki/Spherical_coordinate_system ).这是因为从角度到球面系统的原始转换是使用极坐标/方位角球面角完成的,它们与纬度/经度角不同(wiki it https://en.wikipedia.org/wiki/Spherical_coordinate_system )。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.