Skip to content

polygonRotate

Rotates a polygon around a given origin.

Rotates every point of a polygon by the same angle (radians) around an origin, which defaults to [0, 0]. Here the dashed shape turns 30° about its own center into the solid one. largestRect tries candidate rectangles at many angles this way.

import {polygonRotate} from "@d3plus/math";

const poly = [
  [60, 70],
  [200, 60],
  [210, 130],
  [90, 150],
];
polygonRotate(poly, Math.PI / 6, [140, 100]);

Parameters

import {polygonRotate} from "@d3plus/math";
polyrequiredArray.<Point>

The polygon to be rotated, which should be an Array of [x, y] values.

alpharequirednumber

The angle in radians to rotate.

originPointDefault ...

The origin point of the rotation, which should be an [x, y] formatted Array.