I needed a polygon library for my latest fun project (a TypeScript Build Engine). Google and NPM showed me the way to PolyK.JS, a very simple Polygon library that can do calculations on simple polygons, including Convex ones.
To my suprise, the library includes TypeScript definitions making the lib super easy to consume for my application. Supported operations include:
Gets the area of the polygon.
Triangulates the simple polygon
Slices the polygon.
Finds the closest point on the polygon given the intersection of a ray.
Finds the closest edge of the polygon.
Checks if a given point is within the polygon.
The library assumes that the polygon’s vertices are defined in an number array of X,Y coordinates. Super easy to use and highly recommended!