convex-polygon-scaler

v1.0.2
Convex polygon scaler by a fixed amount
scale 2D polygon convex geometry

Convex polygon scaler

Scale a convex polygon by a fixed amount.

Screenshot

(demo)

How does it differs from scale?

This method is area independent.

Such as the distance between the middle point of an edge of the original quad and the middle point of the respective edge of the scaled polygon is always fixed and is not dependent by the area of the polygon.

Usage example

Works in node.js and in the browser.

Polygon is a list of 2D vectors [x,y] in clockwise or counter-clockwise order.

const _polygon = [[100, 100], [100, 200], [200, 200], [200, 100]]
const dwarf = polygonScaler(polygon, -10)
// [[110,190],[190,190],[190,110],[110,110]]

Credits

Written in Typescript with @thi.ng umbrella library.

npm i convex-polygon-scaler

Metadata

  • ISC
  • Whatever
  • alberto
  • released 10/20/2019

Downloads

Maintainers