【问题标题】:What's the correct way to create a rectangle from an origin point and an end point with Python?用Python从起点和终点创建矩形的正确方法是什么?
【发布时间】:2022-01-10 04:59:59
【问题描述】:

假设我们有以下坐标;基于角度的起点和终点:[(37.040893, -7.83197), (37.042393, -7.83197)]。在地图中,我将它们绘制如下:

如下图所示,我能够成功获得终点,并且效果很好:

import math

end_lat = origin_point[0] + length * math.sin(math.radians(angle))
end_lon = origin_point[1] + length * math.cos(math.radians(angle))

但我想根据原点和终点创建一个长度为x meters、宽度为6 meters 的矩形。而起点和终点都在其顶点的中心。下图解释了我正在尝试做的事情:

现在,我发现纬度 1 度等于 110.574km,经度 1 度等于 111.320*cos(latitude)km。而且,我对数学不太熟悉,我不应该线性地(盲目地)解决这个问题。 我该如何解决这个问题并确保一切正常?

【问题讨论】:

  • 我建议不要自己做数学,而是找一个库函数为你做。
  • 如果你盲目地这样做,你不能确定它是否完美。您需要充分了解问题,才能知道您的代码正在做它应该做的事情。
  • 如图所示,这 2 个点是否总是沿北/南完美运行?如果没有,我认为这个问题会变得更加困难。
  • 如果您将公式中的length 替换为3 metersmath.radians(angle) 替换为math.radians(angle + 90),您将获得原点左侧矩形角的坐标。如果将length替换为3 meters,将角度替换为math.radians(angle - 90),则得到原点右侧矩形角的坐标。
  • 然后,如果您将origin_point 替换为公式中的这两个角之一,您将得到其余两个角之一。

标签: python math geometry maps coordinates


【解决方案1】:

如果您不想使用适当的库,请查看Movable Type Scripts page 的公式。

a)如果您从起点到目的地有方位,请进一步使用它,否则使用方位部分(那里的 JS 脚本)中的公式计算它

 θ = atan2( sin Δλ ⋅ cos φ2 , cos φ1 ⋅ sin φ2 − sin φ1 ⋅ cos φ2 ⋅ cos Δλ )
where   φ1,λ1 is the start point, φ2,λ2 the end point 
(Δλ is the difference in longitude)

b) 获取垂直方位为

θ1 = θ + Pi/2
θ2 = θ - Pi/2

c) 查找Destination point given distance and bearing from start point

φ2 = asin( sin φ1 ⋅ cos δ + cos φ1 ⋅ sin δ ⋅ cos θ )
λ2 = λ1 + atan2( sin θ ⋅ sin δ ⋅ cos φ1, cos δ − sin φ1 ⋅ sin φ2 )
where   φ is latitude, λ is longitude, θ is the bearing (clockwise from north), 
δ is the angular distance d/R; d being the distance travelled, R the earth’s radius

d=3 m,R=6371000 m,起始坐标和θ1、θ2方位角得到矩形角,然后用目标坐标重复。

d) 对于相当小的距离,目标点的近似值是好的,否则您可以在目标点使用真正的方位(因为 Dest-Src 方位与 S-D 方位有点不同)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多