Skip to content

translate

A matrix that moves points by (tx, ty).

Available since v3.1.5

import { translate } from '@helpers4/geometry';
// or, from the all-in-one package (same code, one install):
import { translate } from 'helpers4/geometry';
translate(tx: number, ty: number): Matrix
ParameterTypeDescription
txnumberHorizontal offset
tynumberVertical offset

Matrix — The translation matrix

e and f hold the offset.

applyToPoint(translate(10, 5), { x: 1, y: 1 }) // => { x: 11, y: 6 }

Move up and to the left.

applyToPoint(translate(-1, -1), { x: 0, y: 0 }) // => { x: -1, y: -1 }

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