title: check if point lies in polygon lua
body: <p>How to check if a point lies inside a polygon or some other shapes like star? Anything with multiple vertices but they are connected. After googling for straight 2 hours. This is the code I came up with so far. It's not working the way I want it to work. Sometimes it returns true even if the point does not lie inside polygon. Here's the code. </p>
  
  <pre><code>function isPlayerinBounds (point, vertices)
      local len = #vertices
      local j = 0
      for i=1, len do
          if i == 1 then
              j = len -1
          end
  
          local result = false
          local ix, iy, jx, jy = vertices[i][1], vertices[i][2], vertices[j][1], vertices[j][2]
  
          local tx, ty = point[1], point[2]
  
          if(((iy&lt; ty and jy&gt;=ty) or (jy&lt; ty and iy&gt;=ty) and (ix&lt;=tx or jx&lt;=tx)) then
  
              j = i
              return true
  
          end
  
      end
  
  
      return false
  
  end
  </code></pre>
  
  <p><a href="http://i.stack.imgur.com/bxa3b.png" rel="nofollow">It can be something like this</a></p>