Skip to content

Instantly share code, notes, and snippets.

@thejambi
thejambi / point_in_polygon_using_winding_number.js
Created July 16, 2020 18:30 — forked from vlasky/point_in_polygon_using_winding_number.js
JavaScript implementation of winding number algorithm to determine whether a point is inside a polygon
//JavaScript implementation of winding number algorithm to determine whether a point is inside a polygon
//Based on C++ implementation of wn_PnPoly() published on http://geomalgorithms.com/a03-_inclusion.html
function pointInPolygon(point, vs) {
var x = parseFloat(point[0]), y = parseFloat(point[1]);
var wn = 0;
for (var i = 0, j = vs.length - 1; i < vs.length; j = i++) {
var xi = parseFloat(vs[i][0]), yi = parseFloat(vs[i][1]);