Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

point-polygon-distance

hanasarbortova13MIT License0.0.0

Compute distance of a point from an arbitray shaped polygon

distance, point, polygon

readme

point-polygon-distance

Compute distance of a point from an arbitrary shaped polygon

Example

var ppDist = require("./point-polygon-distance.js")

var polygon = [ [0,0],
                [20,0],
                [10,10],
                [0,10]
                ];

var point = [-5,5];

console.log(ppDist(polygon,point,"CCW"))

Install

npm install point-polygon-distance

API

require("point-polygon-distance")(polygon,point,"CCW")

Compute distance of a point from an arbitrary shaped polygon (either perpendicular distance from a line segment (if projection exists) or distance from the nearest vertex)

  • polygon list of vertices (CW or CCW order)
  • point a point to be tested
  • orientation either "CW" or "CCW" indicating the vertices list orientation

Returns A positive number indicating the point-polygon distance for point outside polygon. Negative number for a point inside polygon(absolute value is equal to the distance to the nearest edge)

Credits

(c) 2013 Hana Sarbortova. MIT License