What is point-in-polygon?
The point-in-polygon npm package is a utility for determining whether a given point lies inside a polygon. This can be useful in various applications such as geographical mapping, collision detection in games, and more.
What are point-in-polygon's main functionalities?
Check if a point is inside a polygon
This feature allows you to check if a given point is inside a specified polygon. The function returns true if the point is inside the polygon and false otherwise.
const inside = require('point-in-polygon');
const point = [1, 1];
const polygon = [[0, 0], [2, 0], [2, 2], [0, 2]];
console.log(inside(point, polygon)); // true
Other packages similar to point-in-polygon
point-in-polygon-hao
The point-in-polygon-hao package provides similar functionality to point-in-polygon, allowing you to check if a point is inside a polygon. It is a lightweight and efficient alternative.
robust-point-in-polygon
The robust-point-in-polygon package offers a more robust solution for checking if a point is inside a polygon. It handles edge cases and numerical precision issues better than point-in-polygon.
turf-inside
The turf-inside module is part of the Turf.js library, which provides advanced geospatial analysis tools. It offers more comprehensive geospatial functionalities compared to point-in-polygon, including point-in-polygon checks.
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)
]);
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