【问题标题】:Compute equidistant GPS point around a center计算围绕中心的等距 GPS 点
【发布时间】:2024-01-02 05:54:01
【问题描述】:

我对一些 GPS 计算有疑问。 我的问题如下:

我有一个特定的点 P,我想计算 P 周围的 N 个点。

这是算法:

P = (x, y) // latitude, longitude
N = 8
angle_size = 360/N

points = []

for i in 1..N
    points.push compute_100meter(P, angle_size*i)
end

在这个例子中,我试图计算距离 P 100 米内的 8 个等距点。

有人知道 ruby gem 允许我这样做吗? 我的问题是写compute_100meter的内容

编辑:

我必须考虑地球曲率并以度数(纬度,经度)获取点坐标。

【问题讨论】:

  • 你不需要 gem,这是一个简单的几何问题。 100m是你的半径。在给定角度的情况下,只需查找方程式即可计算出距圆心 100m 的点。
  • 我必须考虑地球曲率,我编辑了我的问题。
  • 你是对的,我很抱歉。我明白为什么你现在需要一个代码库,因为你不会总是在赤道附近进行计算,那里 100m 大约类似于几何问题。

标签: ruby gps gem geometry coordinates


【解决方案1】:

只要半径足够小(应该是 100 米,除非你就在北极或南极旁边),一个简单的线性近似应该足够好:

def perimeter_point(lat, lon, angle, radius)
    # convert angle from degrees to radians
    angle *= Math::PI / 180
    # convert meters to degrees approximately, assuming spherical Earth
    radius /= 6371000 * Math::PI / 180
    # calculate relative length of the circle of longitude compared to equator
    scale = Math.cos( lat * Math::PI / 180 );
    # add offsets to longitude and latitude and return them
    # (I'm assuming that angle = 0 means due east)
    lat += radius * Math.sin(angle)
    lon += radius * Math.cos(angle) / scale
    return lat, lon
end

请注意,如果您的中心点在 180 度子午线附近,这可能会返回低于 -180 或高于 +180 的经度。如果这是一个问题,请检查它并根据需要进行标准化。 (如果中心点在北极或南极附近,则输出纬度超出 ±90 范围在技术上也是可行的,但无论如何我使用的近似值在两极附近都会失效。)

【讨论】:

    最近更新 更多