title: Finding if point is in 3D poly in python
body: <p>I am trying to find out whether a point is in a 3D poly.  I had used another script I found online to take care of a lot of the 2D problems using ray casting.  I was wondering how this could be changed to work for 3D polygons.  I'm not going to be looking at really strange polygons with a lot of concavity or holes or anything.  Here is the 2D implementation in python: </p>
  
  <pre><code>def point_inside_polygon(x,y,poly):
  
      n = len(poly)
      inside =False
  
      p1x,p1y = poly[0]
      for i in range(n+1):
          p2x,p2y = poly[i % n]
          if y &gt; min(p1y,p2y):
              if y &lt;= max(p1y,p2y):
                  if x &lt;= max(p1x,p2x):
                      if p1y != p2y:
                          xinters = (y-p1y)*(p2x-p1x)/(p2y-p1y)+p1x
                      if p1x == p2x or x &lt;= xinters:
                          inside = not inside
          p1x,p1y = p2x,p2y
  
      return inside
  </code></pre>
  
  <p>Any help would be greatly appreciated!  Thank you. </p>