简体   繁体   English

3d 多边形 - python 中的多边形相交

[英]3d polygon - polygon intersection in python

I'm trying to find the intersection of two 3d polygons that I have the XYZ coordinates for.我试图找到我有 XYZ 坐标的两个 3d 多边形的交集。

I searched for hours but didn't found a good solution that meets my requirements.我搜索了几个小时,但没有找到满足我要求的好解决方案。 As a final result, I want something like Shapely where I can give my XYZ coordinates of the two polygons and get as result the coordinates of the intersection.作为最终结果,我想要像 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)

Does anyone have a suggestion or alternative library where I can achieve this with?有没有人有建议或替代库,我可以用它来实现这一目标? Thanks in advance :)提前致谢 :)

This library solved my problem: https://github.com/GouMinghao/Geometry3D这个库解决了我的问题: https : //github.com/GouMinghao/Geometry3D

I'm posting my code here also because their aren't a lot of examples of this specific problem online:我在这里发布我的代码也是因为他们在网上没有很多关于这个特定问题的例子:

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()```

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM