Created
October 11, 2013 09:54
-
-
Save ericdum/6932317 to your computer and use it in GitHub Desktop.
Point in Polygon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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