https://github.com/kevingodell/polygon-points
Determine if an x y coordinate exists in a polygon. This is being used in a motion detection project where specific regions of an image are being filtered and measured. It works fast when iterating pixels because it caches the bounding box value and uses it to quickly eliminate non-targeted pixels from unnecessary difference calculations.
https://github.com/kevingodell/polygon-points
detection motion nodejs pixels points polygon
Last synced: 5 months ago
JSON representation
Determine if an x y coordinate exists in a polygon. This is being used in a motion detection project where specific regions of an image are being filtered and measured. It works fast when iterating pixels because it caches the bounding box value and uses it to quickly eliminate non-targeted pixels from unnecessary difference calculations.
- Host: GitHub
- URL: https://github.com/kevingodell/polygon-points
- Owner: kevinGodell
- License: mit
- Created: 2017-10-12T01:28:04.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2023-04-19T07:08:35.000Z (about 3 years ago)
- Last Synced: 2025-09-03T04:24:33.984Z (11 months ago)
- Topics: detection, motion, nodejs, pixels, points, polygon
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/polygon-points
- Size: 419 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# polygon-points
###### [](https://travis-ci.org/kevinGodell/polygon-points) [](https://ci.appveyor.com/project/kevinGodell/polygon-points/branch/master) [](https://github.com/kevinGodell/polygon-points/issues) [](https://raw.githubusercontent.com/kevinGodell/polygon-points/master/LICENSE) [](https://greenkeeper.io/)
Determine if an x y coordinate exists in a polygon. This is being used in a motion detection project where specific regions of an image are being filtered and measured. It works fast when iterating pixels because it caches the bounding box value and uses it to quickly eliminate non-targeted pixels from unnecessary difference calculations. It is designed to be used with positive integer values starting with an x y value of 0 0 at the top left.
### installation:
```
npm install polygon-points --save
```
### usage:
```javascript
const PP = require('polygon-points');
const polygonPoints = new PP([{x: 0, y: 0}, {x: 0, y: 100}, {x: 100, y: 100}, {x: 100, y: 0}]);
//public methods
//check if a point exists in the polygon
polygonPoints.containsPoint(1, 1);//returns true
//get bounding box of polygon
polygonPoints.boundingBox;//returns an array of 4 x y coordinates
//get total number of points that exist in polygon
polygonPoints.pointsLength;//returns 10000
//set vertexes after creating polygonPoints object
polygonPoints.vertexes = [{x: 0, y: 0}, {x: 0, y: 100}, {x: 100, y: 100}, {x: 100, y: 0}];
//get minX, maxX, minY, and maxY unsigned integers of bounding box
polygonPoints.minX, polygonPoints.maxX, polygonPoints.minY, polygonPoints.maxY;
```