Skip to content

rotate

A matrix that rotates points around the origin. With the y axis pointing down (screen, CSS, SVG), a positive angle turns clockwise, like CSS rotate().

Available since v3.1.5

import { rotate } from '@helpers4/geometry';
// or, from the all-in-one package (same code, one install):
import { rotate } from 'helpers4/geometry';
rotate(radians: number): Matrix
ParameterTypeDescription
radiansnumberThe angle, in radians

Matrix — The rotation matrix

With y pointing down, a positive angle turns clockwise, like CSS rotate().

applyToPoint(rotate(Math.PI / 2), { x: 1, y: 0 }) // => { x: 0, y: 1 } (rounded)

Convert degrees to radians first.

rotate((45 * Math.PI) / 180)

A 2D affine transformation, in the layout of CSS and SVG matrix(a, b, c, d, e, f):

x' = a·x + c·y + e
y' = b·x + d·y + f
interface Matrix {
  a: number;
  b: number;
  c: number;
  d: number;
  e: number;
  f: number;
}

View source on GitHub