znj 1 anno fa
parent
commit
1fae4ceaba
1 ha cambiato i file con 17 aggiunte e 0 eliminazioni
  1. 17 0
      format_convert/utils.py

+ 17 - 0
format_convert/utils.py

@@ -38,6 +38,23 @@ if get_platform() == "Linux":
     import resource
 import math
 
+from shapely.geometry import Polygon
+
+def has_intersection(poly1, poly2):
+    """
+    判断两个四边形是否有交集。
+    参数:
+        poly1, poly2: list of tuples, 每个tuple表示一个顶点的(x, y)坐标。
+        例如: [(x1, y1), (x2, y2), (x3, y3), (x4, y4)]
+    返回:
+        bool: 如果两个四边形有交集则返回True,否则返回False。
+    """
+    # 创建Shapely多边形对象
+    polygon1 = Polygon(poly1)
+    polygon2 = Polygon(poly2)
+
+    # 使用intersects方法判断是否有交集
+    return polygon1.intersects(polygon2)
 
 def judge_error_code(_list, code=[0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16]):
     """