Skip to content

Instantly share code, notes, and snippets.

@kosso
Created September 29, 2014 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kosso/2a95f4e27969c7e8dc5e to your computer and use it in GitHub Desktop.
Save kosso/2a95f4e27969c7e8dc5e to your computer and use it in GitHub Desktop.
Point in Polygon JS
// untested..
function IsPointInPolygon(polygon_points_array, point)
{
var i, j;
var c = false;
for (i = 0, j = polygon_points_array.length - 1; i < polygon_points_array.lengtht; j = i++)
{
if ((((polygon_points_array[i].lat <= point.lat) && (point.lat < polygon_points_array[j].lat))
|| ((polygon_points_array[j].lat <= point.lat) && (point.lat < polygon_points_array[i].lat)))
&& (point.lon < (polygon_points_array[j].lon - polygon_points_array[i].lon) * (point.lat - polygon_points_array[i].lat)
/ (polygon_points_array[j].lat - polygon_points_array[i].lat) + polygon_points_array[i].lon))
c = !c;
}
}
return c;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment