Python中如何求两等高线图的多个交点

2024-04-16 12:08:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我用Python在同一个图上绘制了两个等高线图。这两个图有多个交点。我已经找到了一个交叉点,但我想找到所有可能的交叉点。你知道吗

下面是我用来寻找一个交点的代码:

 from shapely import geometry
 def findIntersection(contour1, contour2):
      p1 = contour1.collections[0].get_paths()[0]
      v1 = p1.vertices
      p2 = contour2.collections[0].get_paths()[0]
      v2 = p2.vertices
      poly1 = geometry.LineString(v1)
      poly2 = geometry.LineString(v2)
      intersection = pol1.intersection(poly2)
      return intersection
 intersection_example = findIntersection(contour1, contour2)
 print(list(intersection_example.coords))

以下是输出:

[(2.280337504875689, 0.1641120502440566)]

如您所见,代码输出单个解决方案对,但我需要所有解决方案对。你知道吗

Here is the image of the contour plot that I wish to find all the intersection points for


Tags: 代码getcollectionsv1pathsp2geometryp1