70515

Python Shapely intersection: parallel planes

Question:

I'm working on determining relationships (boundary/interior intersections) between two 3D objects (triangular faces) and stumbled on <a href="http://pypi.python.org/pypi/Shapely" rel="nofollow">shapely</a>, 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.

Answer1:

According to the <a href="http://toblerity.github.com/shapely/manual.html#geometric-objects" rel="nofollow">Shapely manual</a>, it states that the following for the z coordinate plane for geometric objects:

<blockquote>

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

</blockquote>

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 <a href="https://stackoverflow.com/questions/1076778/good-geometry-library-in-python" rel="nofollow">here</a>.

Recommend

  • Missing Clickonce prerequisites in Visual Studio 2013
  • Sending Special characters as a message;
  • Detect if two line segments intersect using Cramer
  • Deserializing JSON to a .net base class with JSON.net
  • Python : How to center Label in tkinter window
  • What does this mean? (Google Maps API)
  • What is the best way to join ordered arrays?
  • Diagonal of polygon is inside or outside?
  • Finding all the overlapping groups of dictionary keys
  • Restrict an object to stay within another object
  • How to fail Phing without triggering backtrace
  • Linq Full Outer Join on Two Objects
  • How to get the index of element in the List in c#
  • Removing Duplicate Geometries
  • Roxygen error “Skipping invalid path”
  • How to run “Deployd” on port 80 instead of port 5000 in webserver.
  • Time complexity of a program which involves multiple variables
  • Admob requires api-13 or later can I not deploy on old API-8 phones?
  • output of program is not same as passed argument
  • Does CUDA 5 support STL or THRUST inside the device code?
  • Join two tables and save into third-sql
  • How to model a transition system with SPIN
  • ActionScript 2 vs ActionScript 3 performance
  • Statically linking a C++ library to a C# process using CLI or any other way
  • ORA-29908: missing primary invocation for ancillary operator
  • How can I estimate amount of memory left with calling System.gc()?
  • Why winpcap requires both .lib and .dll to run?
  • Apache 2.4 - remove | delete | uninstall
  • Return words with double consecutive letters
  • Python: how to group similar lists together in a list of lists?
  • Bitwise OR returns boolean when one of operands is nil
  • sending mail using smtp is too slow
  • Busy indicator not showing up in wpf window [duplicate]
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • How can I use `wmic` in a Windows PE script?
  • UserPrincipal.Current returns apppool on IIS
  • Converting MP3 duration time
  • Conditional In-Line CSS for IE and Others?