Skip to content

pointRotate

Rotates a point around a given origin.

Rotates a point by an angle in radians around the origin [0, 0] by default. A quarter turn (π/2) moves [100, 0] onto the y axis; the tiny residue on x is ordinary floating-point error.

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

pointRotate([100, 0], Math.PI / 2);

The third argument sets the center of rotation, so the point swings around [40, 40] instead of the origin. Radial layouts rotate label anchors this way.

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

pointRotate([80, 40], Math.PI / 4, [40, 40]);

Parameters

import {pointRotate} from "@d3plus/math";
prequiredPoint

The point to be rotated, which should always be an [x, y] formatted Array.

alpharequirednumber

The angle in radians to rotate.

originPointDefault ...

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