1.0.2 • Published 5 years ago

convex-polygon-scaler v1.0.2

Weekly downloads
2
License
ISC
Repository
-
Last release
5 years ago

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.