gpt4 book ai didi

python - 得到一条直线上的n个点

转载 作者:行者123 更新时间:2023-11-28 21:24:28 25 4
gpt4 key购买 nike

如果我有一条由起点和终点坐标定义的线,考虑到地球的曲率,我如何在该线上获得 n 个等距点?

我正在寻找一种算法,和/或实现它的 python 库。

最佳答案

使用 geographiclib ,GeographicLib 的 python 实现,我能够做到这一点:

from geographiclib.geodesic import Geodesic

number_points = 10

gd = Geodesic.WGS84.Inverse(35, 0, 35, 90)
line = Geodesic.WGS84.Line(gd['lat1'], gd['lon1'], gd['azi1'])

for i in range(number_points + 1):
point = line.Position(gd['s12'] / number_points * i)
print((point['lat2'], point['lon2']))

输出:

(35.0, -7.40353472481637e-21)
(38.29044006500327, 7.8252809205988445)
(41.01134777655358, 16.322054184499173)
(43.056180665524245, 25.451710440063902)
(44.328942450747135, 35.08494460239694)
(44.76147256654079, 45.00000000000001)
(44.328942450747135, 54.91505539760305)
(43.05618066552424, 64.54828955993611)
(41.01134777655356, 73.67794581550085)
(38.290440065003274, 82.17471907940114)
(34.99999999999999, 90.0

关于python - 得到一条直线上的n个点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16015533/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com