3

我试图弄清楚纬度/经度点是否包含在由代表地球上的点的顶点定义的多边形内(也是纬度/经度,按顺时针顺序排列)。这对于可以映射到 2D 纬度/经度空间的多边形来说是微不足道的。

这变得越来越困难的是圆圈(现在切换回 3D),它可能会从一个极点到另一个极点,覆盖半个地球。转换为纬度/经度看起来像一个正弦波。多边形测试中的 2D 点不再适用于这种情况。是否存在解决此问题的算法?

================== 澄清以下评论: =================== 多边形定义为(lon, lat) 对以度为单位,即 (60, 90), (60, 110), (-30, 110), (-30, 90)。

我确实有实现光线投射算法的代码,并且有效。但是,地球表面上的某些多边形不会转换为 2D 空间中的封闭多边形。

4

3 回答 3

1

As stated by denniston.t, if you are only interested in circles, and you have a radius, you can simply check if the Great Circle Distance between the center point and the point is less than the radius. To find the great circle distance you typically use the Haversine Formula. The following is my implementation in python:

from math import radians, sin, cos, asin, sqrt

def haversine(point1, point2):
    """Gives the distance between two points on earth.

    The haversine formula, given two sets of latitude and longitude,
    returns the distance along the surface of the earth in miles,
    ignoring potential changes in elevation. The points must be in
    decimal degrees.
    """
    earth_radius_miles = 3956
    lat1, lon1 = (radians(coord) for coord in point1)
    lat2, lon2 = (radians(coord) for coord in point2)
    dlat, dlon = (lat2 - lat1, lon2 - lon1)
    a = sin(dlat/2.0)**2 + cos(lat1) * cos(lat2) * sin(dlon/2.0)**2
    great_circle_distance = 2 * asin(min(1,sqrt(a)))
    d = earth_radius_miles * great_circle_distance
    return d
于 2011-11-18T21:02:00.493 回答
0

如果您在球体表面上绘制了圆的中心点和半径,请计算中心点和目标点之间的大圆距离。如果小于圆的半径,则目标点在圆内。

这不会推广到在您的球体上绘制的任意多边形,但您只询问了圆圈,所以我不知道这对您是否重要。

于 2011-11-18T19:59:08.690 回答
-1
containsLocation(point:LatLng, polygon:Polygon)
于 2012-07-13T04:21:01.903 回答