Python计算两个大圆的交点 [英] Python calculate point of intersection of two great circles

查看:524
本文介绍了Python计算两个大圆的交点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试计算两个大圆的交点(以度为单位的经度和纬度),每个交点由圆上的两个点定义.我一直在尝试此处中概述的方法. 但是我得到的答案是不正确的,我的代码在下面,有人看到我出了错吗?

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).

推荐答案

DSM在上面的注释中的解决方案,您的角度以度为单位,而sin和cos期望弧度. 还有这行

Solution from DSM in comments above, your angles are in degrees while sin and cos expect radians. Also the line

X1 = L / abs(L)

应该是

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

这篇关于Python计算两个大圆的交点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆