Skip to content

@technobuddha > library > Geometry > Polygon

Function: regularPolygon()

ts
function regularPolygon(
   sides: number, 
   radius: number, 
   options: OriginOptions): Polygon;

Defined in: regular-polygon.ts:24

Generates a regular polygon.

Parameters

ParameterTypeDefault valueDescription
sidesnumber3The number of sides of the polygon (must be at least 3).
radiusnumber1The radius of the polygon (distance from the origin to each vertex).
optionsOriginOptions{}see OriginOptions

Returns

Polygon

A regular polygon.

Throws

TypeError If the number of sides is less than 3.

Example

typescript
regularPolygon(4, 2);
// [
//   { x: 2, y: 0 },
//   { x: 0, y: 2 },
//   { x: -2, y: 0 },
//   { x: 0, y: -2 }
// ]