Skip to content

Instantly share code, notes, and snippets.

@unstoppablecarl
Created January 12, 2013 08:28
Show Gist options
  • Save unstoppablecarl/4516760 to your computer and use it in GitHub Desktop.
Save unstoppablecarl/4516760 to your computer and use it in GitHub Desktop.
function pointInPolygon (point, polygon){
var i,
j,
c = 0,
pointX = point.x,
pointY = point.y;
for (i = 0, j = polygon.length - 1, len = polygon.length; i < len; j = i++){
if (((polygon[i].y > pointY) != (polygon[j].y > pointY)) && (pointX < (polygon[j].x - polygon[i].x) * (pointY - polygon[i].y) / (polygon[j].y - polygon[i].y) + polygon[i].x)){
c = !c;
}
}
return c;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment