Created
September 29, 2014 16:34
-
-
Save kosso/2a95f4e27969c7e8dc5e to your computer and use it in GitHub Desktop.
Point in Polygon JS
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
// 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