determine if a point is inside a polygon
JavaScript
Latest commit e1888ce Jul 6, 2016 @substack 1.0.1
Permalink
Failed to load latest commit information.
example modernize Jun 13, 2015
test modernize Jun 13, 2015
LICENSE rename Jul 6, 2016
index.js initial translation Dec 31, 2011
package.json 1.0.1 Jul 6, 2016
readme.markdown modernize Jun 13, 2015

readme.markdown

point-in-polygon

Determine if a point is inside of a polygon.

This module casts a ray from the inquiry point and counts intersections, based on this algorithm.

example

var inside = require('point-in-polygon');
var polygon = [ [ 1, 1 ], [ 1, 2 ], [ 2, 2 ], [ 2, 1 ] ];

console.dir([
    inside([ 1.5, 1.5 ], polygon),
    inside([ 4.9, 1.2 ], polygon),
    inside([ 1.8, 1.1 ], polygon)
]);

output:

[ true, false, true ]

methods

var inside = require('point-in-polygon')

inside(point, polygon)

Return whether point is contained in polygon.

point should be a 2-item array of coordinates.

polygon should be an array of 2-item arrays of coordinates.

install

npm install point-in-polygon

license

MIT