Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

determine if a point is inside a polygon

branch: master

example file

latest commit 4e4a4fd7b6
James Halliday authored January 01, 2012
Octocat-spinner-32 example example file January 01, 2012
Octocat-spinner-32 test a package.json December 31, 2011
Octocat-spinner-32 README.markdown example file January 01, 2012
Octocat-spinner-32 index.js initial translation December 30, 2011
Octocat-spinner-32 package.json a readme January 01, 2012
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
Something went wrong with that request. Please try again.