3d 多边形 - python 中的多边形交集
3d polygon - polygon intersection in python
我试图找到我具有 XYZ 坐标的两个 3d 多边形的交集。
我搜索了几个小时,但没有找到满足我要求的好的解决方案。
作为最终结果,我想要类似 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)
有没有人有我可以用来实现此目的的建议或替代库?
提前致谢:)
这个库解决了我的问题: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()
我试图找到我具有 XYZ 坐标的两个 3d 多边形的交集。
我搜索了几个小时,但没有找到满足我要求的好的解决方案。 作为最终结果,我想要类似 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)
有没有人有我可以用来实现此目的的建议或替代库? 提前致谢:)
这个库解决了我的问题: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()