Python形状相交:平行平面 [英] Python Shapely intersection: parallel planes

查看:599
本文介绍了Python形状相交:平行平面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究确定两个三维物体(三角形面)之间的关系(边界/内部交点),并偶然发现了很好看,我有兴趣使用它来代替实现我自己的点/段/光线/三角交集函数。



然而,我正在运行进入以下问题:

 >>> 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

我似乎遇到的问题是这两个多边形在它们的2D正交投影(相同的三角形)上是相等的,但是在不同的平面上(一个在Z = 1时,另一个在Z = 0时),但是很好地说它们是相等的并且相交。
$ b

有没有什么魔法可以让我们在3个维度上进行思考?我一直在使用谷歌搜索,但我目前看到的每个例子都只有两个维度。

根据<一个href =http://toblerity.github.com/shapely/manual.html#geometric-objects =nofollow noreferrer>匀称手动,它指出以下为z坐标平面的几何对象:


构建实例时可以使用第三个z坐标值,但对几何分析没有影响。所有操作都在xy平面上执行。 匀称可能不适合你。当然,您可以尝试将多边形的点作为列表并将其与其他多边形进行比较。然而,如果你想有一个可以处理z维度的Python几何库,你可以找到一些这里


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.

解决方案

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.

这篇关于Python形状相交:平行平面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆