Skip to content

Instantly share code, notes, and snippets.

@ericdum
Created October 11, 2013 09:54
Show Gist options
  • Save ericdum/6932317 to your computer and use it in GitHub Desktop.
Save ericdum/6932317 to your computer and use it in GitHub Desktop.
Point in Polygon
function isPointInPath(x, y, poly){
var num = poly.length,
i = 0,
j = num - 1,
c = false;
for( ; i < num; ++i ) {
if ( ((poly[i][1] > y) != (poly[j][1] > y))
&& (x < (poly[j][0] - poly[i][0]) * (y - poly[i][1]) / (poly[j][1] - poly[i][1]) + poly[i][0]))
c = !c;
j = i;
}
return c;
}
b = [[0,0],[1,3],[2,0],[3,3]];
console.log(isPointInPath(3,6, a));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment