Shapely intersection: parallel planes

浪尽此生 提交于 2019-12-14 01:22:33

问题


I'm working on determining relationships (boundary/interior intersections) between two 3D objects (triangular faces) and stumbled on Shapely, which I am interested in using instead of implementing my own point/segment/ray/triangle intersection functions.

However, I'm running into the following problem:

>>> from shapely.geometry import Polygon
>>> poly = Polygon([(0,1,1),(1,-1,1),(-1,-1,1)])
>>> poly2 = Polygon([(0,1,0),(1,-1,0),(-1,-1,0)])
>>> poly.intersects(poly2)
True
>>> poly.equals(poly2)
True

The problem I seem to be running into is that the two polygons are equal in their 2D orthogonal projections (same triangle), but in different planes (one's at Z=1, other at Z=0), but Shapely is saying they're equal and intersect.

Is there some magic I'm missing to make shapely think in 3 dimensions? I've been googling, but every example I've seen so far is only in two dimensions.


回答1:


According to the Shapely manual, it states that the following for the z coordinate plane for geometric objects:

A third z coordinate value may be used when constructing instances, but has no effect on geometric analysis. All operations are performed in the x-y plane.

If your calculations require the z coordinate plane, then Shapely might not be for you. Of course, you could try to get the points of the polygon as a list and compare it to other polygons. However, if you want to have a Python geometric library that can handle the z dimension, you can find some here.



来源:https://stackoverflow.com/questions/9470406/shapely-intersection-parallel-planes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!