Skip to content

invert

The matrix that undoes m, e.g. to turn a pointer position on screen back into the coordinates of a transformed layer.

A matrix that flattens the plane onto a line or a point (determinant 0, like scale(0)) cannot be undone. There is no tolerance: a nearly flat matrix is inverted, with very large values, as long as they stay finite.

Available since v3.1.5

import { invert } from '@helpers4/geometry';
// or, from the all-in-one package (same code, one install):
import { invert } from 'helpers4/geometry';
invert(m: Matrix): Matrix | undefined
ParameterTypeDescription
mMatrixThe matrix to invert

Matrix | undefined — The inverse, or undefined when m cannot be inverted

Invert the layer transform to map screen coordinates back into the layer.

const layer = multiply(translate(100, 50), scale(2));
applyToPoint(invert(layer)!, { x: 120, y: 70 }) // => { x: 10, y: 10 }

A matrix that flattens the plane cannot be undone.

invert(scale(0)) // => undefined

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