Compute distance of a point from an arbitrary shaped polygon
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"))
npm install point-polygon-distance
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 testedorientation
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)
(c) 2013 Hana Sarbortova. MIT License