title: Point inside a polygon javascript
body: <p>I'm working in javascript finding that if the point i have is inside a polygon. I'm using ray-casting algorithm to compare that if the point is inside the polygon or not.</p>
  
  <p>The algo is working perfect for some case. But for some case it show the point is outside even when the points are lying all inside the polygon.</p>
  
  <p>!<a href="https://www.dropbox.com/s/rpxqnw9re3q6vsi/Screen%20Shot.png?dl=0" rel="nofollow">https://www.dropbox.com/s/rpxqnw9re3q6vsi/Screen%20Shot.png?dl=0</a></p>
  
  <p>The area marked A1 is the parent polygon, and A2 and A3 are inside the parent polygon. Below the the function i'm using to check if the point is inside or not</p>
  
  <pre><code>function isPointInside(point, vs)
  {
  // ray-casting algorithm based on
  var x = point[0], y = point[1];
  
  var inside = false;
  for (var i = 0, j = vs.length - 1; i &lt; vs.length; j = i++)
  {
      var xi = vs[i][0], yi = vs[i][1];
      var xj = vs[j][0], yj = vs[j][1];
      var intersect = ((yi &gt; y) != (yj &gt; y))&amp;&amp; (x &lt; (xj - xi) * (y - yi) / (yj - yi) + xi);
      if (intersect) inside = !inside;
  }
  
  return inside;
  };
  </code></pre>
  
  <p>Below are the point array for the parent polygon as well as child polygons</p>
  
  <pre><code> A1 Array 
  0[0, 0] (2)
  1[6096000, 0] (2)
  2[6096000, 0] (2)
  3[6096000, 6096000] (2) 
  4[6096000, 6096000] (2)
  5[0, 6096000] (2)
  6[0, 6096000] (2)
  7[0, 0] (2)
  8[0, 0] (2)
  9[0, 0] (2)
  
  
  A2 Array (10)
   0[0, 0] (2)
   1[0, 3048000] (2)
   2[0, 3048000] (2)
   3[1524000, 3048000] (2)
   4[1524000, 3048000] (2)
   5[1524000, 0] (2)
   6[1524000, 0] (2)
   7[0, 0] (2)
   8[0, 0] (2)
   9[0, 0] (2)
  
  
  A3 Array (10)
   0[4572000, 0] (2)
   1[4572000, 6096000] (2)
   2[4572000, 6096000] (2)
   3[6096000, 6096000] (2)
   4[6096000, 6096000] (2)
   5[6096000, 0] (2)
   6[6096000, 0] (2)
   7[4572000, 0] (2)
   8[4572000, 0] (2)
   9[4572000, 0] (2)
  </code></pre>
  
  <p>Why is that the points of A3 are not considered inside. Is there something wrong in the algo? Any help will be appreciated.</p>