【问题标题】:3d polygon - polygon intersection in python3d 多边形 - python 中的多边形交集
【发布时间】:2021-08-02 19:36:24
【问题描述】:

我试图找到两个 3d 多边形的交点,我有 XYZ 坐标。

我搜索了几个小时,但没有找到满足我要求的好解决方案。 作为最终结果,我想要像 Shapely 这样的东西,我可以在其中给出两个多边形的 XYZ 坐标,并得到交叉点的坐标。

# This code is just for example returns an error because Shapely only works with XY

from shapely.wkt import loads

poly = loads('POLYGON ((0 0 0, 100 0 100, 100 100 100, 0 100 0, 0 0 0))')
poly_horizontal_line = loads('POLYGON ((-50 50 -50, -50 50 150, 150 50 150, 150 50 -50, -50 50 -50))')

intersection = poly_horizontal_line.exterior.intersection(poly)

if intersection.is_empty:
   print("shapes don't intersect")
elif intersection.geom_type.startswith('Multi') or intersection.geom_type == GeometryCollection':
   for shp in intersection:
      print(shp)
else:
   print(intersection)

有没有人可以提供建议或替代库来实现这一目标? 在此先感谢:)

【问题讨论】:

  • 你为什么想要一个不同的库,这不符合你的目的吗?
  • Shapely 仅适用于 2 轴 XY,我需要 XYZ..
  • this 图书馆对你有帮助吗?
  • 嗨,我遇到了这个库,但我认为它不能解决我的问题。我试了一下,终于成功了,谢谢!我也在发布我的解决方案。

标签: python intersection shapely


【解决方案1】:

这个库解决了我的问题:https://github.com/GouMinghao/Geometry3D

我在这里发布我的代码也是因为他们不是很多在线这个特定问题的例子:

from Geometry3D import *

a = Point(0,0,0)
b = Point(1,0,0)
c = Point(1,1,0)
d = Point(0.5,1.5,0)
e = Point(0.25,2,0)
f = Point(0,2,0)
plane1 = ConvexPolygon((a,b,c,d,e,f))

a1 = Point(-0.5,1.2,-0.5)
b1 = Point(1.5,1.2,-0.5)
c1 = Point(1.5,1.2,1.5)
d1 = Point(-0.5,1.2,1.5)
plane2 = ConvexPolygon((a1,b1,c1,d1))

inter = intersection(plane1,plane2)
print(inter) # results I needed



# visualize planes 
r = Renderer()
r.add((plane1,'r',2),normal_length = 0)
r.add((plane2,'b',2),normal_length = 0)
r.show()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-09-30
    • 2012-06-28
    • 1970-01-01
    • 2012-06-05
    • 1970-01-01
    • 1970-01-01
    • 2012-12-15
    • 1970-01-01
    相关资源
    最近更新 更多