All Projects → rowanwins → point-in-polygon-hao

rowanwins / point-in-polygon-hao

Licence: MIT License
A point in polygon library based on the paper "Optimal Reliable Point-in-Polygon Test and Differential Coding Boolean Operations on Polygons" by Hao

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to point-in-polygon-hao

inpoly
A fast 'point(s)-in-polygon' test for MATLAB.
Stars: ✭ 17 (-79.52%)
Mutual labels:  computational-geometry, point-in-polygon
tektosyne
The Tektosyne Library for Java provides algorithms for computational geometry and graph-based pathfinding, along with supporting mathematical utilities and specialized collections.
Stars: ✭ 52 (-37.35%)
Mutual labels:  computational-geometry, point-in-polygon
homog2d
C++ 2D geometry library, handles points, lines, polylines, planar transformations (and other primitives), using homogeneous coordinates. Provided with complete manual and samples.
Stars: ✭ 70 (-15.66%)
Mutual labels:  computational-geometry
home
Community for parametric furniture designs.
Stars: ✭ 44 (-46.99%)
Mutual labels:  computational-geometry
ELEMENTS
The C++ ELEMENTS library contains a suite of sub-libraries to support mathematical functions (elements), data representations (MATAR), and novel mesh classes (geometry and SWAGE) to support a very broad range of element types, numerical methods, and mesh connectivity data structures useful for computational physics and engineering.
Stars: ✭ 13 (-84.34%)
Mutual labels:  computational-geometry
geojson-rbush
GeoJSON implementation of RBush — a high-performance JavaScript R-tree-based 2D spatial index for points and rectangles
Stars: ✭ 60 (-27.71%)
Mutual labels:  computational-geometry
convhull 3d
A header-only C implementation of the Quickhull algorithm for building N-dimensional Convex Hulls and Delaunay meshes
Stars: ✭ 108 (+30.12%)
Mutual labels:  computational-geometry
SplashGeom
Open-source C++ library for geometry and linear algebra
Stars: ✭ 22 (-73.49%)
Mutual labels:  computational-geometry
polytope
Geometric operations on polytopes of any dimension
Stars: ✭ 51 (-38.55%)
Mutual labels:  computational-geometry
3D interactive graphics rendering engine
Develop a 3D interactive graphics rendering engine
Stars: ✭ 31 (-62.65%)
Mutual labels:  computational-geometry
SDLP
Seidel's LP Algorithm: Linear-Complexity Linear Programming for Small-Dimensional Variables
Stars: ✭ 36 (-56.63%)
Mutual labels:  computational-geometry
rdp
A library providing FFI access to fast Ramer–Douglas–Peucker and Visvalingam-Whyatt line simplification algorithms
Stars: ✭ 20 (-75.9%)
Mutual labels:  computational-geometry
bentley-ottmann
simple Java implementation of Bentley-Ottmann sweep line algorithm for listing all intersections in a set of line segments
Stars: ✭ 16 (-80.72%)
Mutual labels:  computational-geometry
PolygonOps.jl
Generic Polygon Operations
Stars: ✭ 19 (-77.11%)
Mutual labels:  point-in-polygon
mcut
A simple and fast library for mesh booleans and more.
Stars: ✭ 57 (-31.33%)
Mutual labels:  computational-geometry
polliwog
2D and 3D computational geometry library
Stars: ✭ 22 (-73.49%)
Mutual labels:  computational-geometry
venn7
A musical interface based on symmetric 7-set Venn diagrams
Stars: ✭ 29 (-65.06%)
Mutual labels:  computational-geometry
polyclip
R package polyclip: a port of the Clipper library for polygon geometry
Stars: ✭ 18 (-78.31%)
Mutual labels:  computational-geometry
MidcurveNN
Computation of Midcurve of Thin Polygons using Neural Networks
Stars: ✭ 19 (-77.11%)
Mutual labels:  computational-geometry
polygon-splitter
A small (<10kb minified) javascript library for splitting polygons by a polyline.
Stars: ✭ 20 (-75.9%)
Mutual labels:  computational-geometry

A small library for detecting in a point lies inside a polygon

Features

  • Works on polygons with holes
  • Works with degenerate/self-intersecting polyons
  • Returns 0 if on the edge
  • Not effected by floating point errors

Usage

Install via npm install point-in-polygon-hao

import inside from 'point-in-polygon-hao'

const polygon = [
  [
    [1, 1],
    [1, 2],
    [2, 2],
    [2, 1],
    [1, 1]
  ]
];

inside([ 1.5, 1.5 ], polygon)
// => true

inside([ 4.9, 1.2 ], polygon)
// => false

inside([1, 2], polygon)
// => 0 to indicate on edge

Note: The input polygon format aligns with the GeoJson specification for polygons. This means that the first and last coordinate in a polygon must be repeated, if not this library will throw an error.

const polygonWithHole = [
  [
    [0, 0], [1, 0], [1, 1], [0, 1], [0, 0]
  ],
  [
    [0.1, 0.1], [0.1, 0.9], [0.9, 0.9], [0.9, 0.1], [0.1, 0.1]
  ]
]

The library does not support multi-polygons.

Comparisons

Some rough comparisons to similar libraries. While point-in-polygon is slightly faster in most cases it does not support polygons with holes or degenerate polygons.

// For a point in a much larger geometry (700+ vertices)
point-in-poly-hao x 474,180 ops/sec ±0.55% (93 runs sampled)
point-in-polygon x 489,649 ops/sec ±0.75% (91 runs sampled)
robust-point-in-polygon x 376,268 ops/sec ±0.79% (89 runs sampled)
// For a point in bounding box check
point-in-poly-hao x 29,365,704 ops/sec ±1.30% (90 runs sampled)
point-in-polygon x 42,339,450 ops/sec ±0.78% (95 runs sampled)
robust-point-in-polygon x 20,675,569 ops/sec ±0.65% (95 runs sampled)

Algorithm

This library is based on the paper Optimal Reliable Point-in-Polygon Test and Differential Coding Boolean Operations on Polygons

Other notes

  • Works irrespective of winding order of polygon
  • Does not appear to be effected by floating point errors compared to point-in-polygon or robust-point-in-polygon
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].