[英]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()```
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.