@mocanvas/editor · function

getPolygonVertices

declare function getPolygonVertices(width: number, height: number, sides: number): Vec[]

The vertices of a regular sides-gon scaled to exactly fill a width × height box, starting at the apex (the -π/2 angle) and running clockwise.

This is the generator behind the triangle, diamond, pentagon, hexagon and octagon outlines, exported so that anything drawing a preview of one of those — a placement ghost, a custom geo type — calls it instead of restating the trigonometry. The result always fills the box exactly, so its bounds are the box.

mocanvas is built by Symbio. Free for non-commercial, non-profit and development use; commercial use needs an agreement. Not affiliated with or endorsed by tldraw.