【问题标题】:algorithm to define a geofence and see if a point is inside/outside it定义地理围栏并查看点是否在其内部/外部的算法
【发布时间】:2012-06-07 00:17:59
【问题描述】:

我正在寻找一种算法,通过我可以创建地理围栏并检查设备是否正在进入/离开围栏。我已经研究过多边形算法中的点(光线投射和缠绕数),但是是否有任何算法可以应用于圆形和任何不规则形状?重要的限制是时间效率。

谢谢。

【问题讨论】:

    标签: algorithm math geo point-in-polygon geofencing


    【解决方案1】:

    下面是简单易懂的c代码算法:

    http://alienryderflex.com/polygon/

    【讨论】:

      【解决方案2】:

      圆很容易(至少如果你假设一个局部平坦的表面)- 只是到一个点的绝对距离。

      如果您需要速度,通常的方法是级联,您首先检查一个圆,或者一个围绕点的正方形,然后是凸多边形,然后是更详细的多边形(如果需要)。

      如果它不是多边形,你如何定义不规则形状?

      请参阅How to test if a point is inside of a convex polygon in 2D integer coordinates?

      【讨论】:

      • 注:它通常不是正方形,而是矩形,通常称为“边界框”。
      • @DavidConrad - 是的,我过于简单化了。或者,它是一个正方形,您只需更改坐标;-)
      • 当然。 :) 我只是想为 OP 提供术语“边界框”和更多信息,这可能对搜索有用,并且觉得不值得单独回答,所以我把它放在这里,作为评论对你的回答。干杯!
      【解决方案3】:

      我为 python 找到了这个解决方案。据我所知,这很有效。

      from shapely.geometry import Point, Polygon
      import matplotlib.path as mpltPath
      from functools import reduce
      import operator
      import math
      coords = [[ 12.934158,77.609316], [ 12.934796,77.609852],[ 12.934183,77.610646], [ 12.933551,77.610100], [12.934158,77.609316]]
      
      #sorting the geofence coords in clockwise direction
      center = tuple(map(operator.truediv, reduce(lambda x, y: map(operator.add, x, y), coords), [len(coords)] * 2))
      coords = sorted(coords, key=lambda coord: (-135 - math.degrees(math.atan2(*tuple(map(operator.sub, coord, center))[::-1]))) % 360)
      
      #Testing if a point inside or outside
      poly = Polygon(coords)
      point = Point(12.933556,77.609854)
      print(coords)
      if(point.within(poly)):
          print("Inside")
      else:
          print("Outside")
      

      谢谢!

      【讨论】:

        【解决方案4】:

        Winding Number Method

        但底线是,出于几何正确性和效率的原因,在确定多边形中是否包含点时,应始终首选缠绕数算法。

        【讨论】:

          【解决方案5】:

          看看四叉树、空间索引、四叉树和 r-tree。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2017-10-09
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2020-09-15
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多