Skip to content

@technobuddha > library > Geometry > Rectangle

Function: largestInscribedRectangle()

ts
function largestInscribedRectangle(polygon: Polygon, options: LargestInscribedRectUnitOptions): Rect | RotatedRect;

Defined in: largest-inscribed-rectangle.ts:98

Computes the largest rectangle that can be inscribed within the given polygon.

Parameters

ParameterTypeDescription
polygonPolygonThe polygon within which to inscribe the rectangle.
optionsLargestInscribedRectUnitOptionsConfiguration options for the computation.

Returns

Rect | RotatedRect

The largest inscribed rectangle.

Throws

Error When polygon has fewer than 3 vertices

Example

typescript
const polygon: Polygon = [
  { x: 0, y: 0 },
  { x: 10, y: 0 },
  { x: 10, y: 10 },
  { x: 0, y: 10 }
];
const rect = largestInscribedRectangle(polygon, { aligned: true });
// rect: { x: 0, y: 0, width: 10, height: 10 }