Skip to content

scale

A matrix that scales points from the origin.

Available since v3.1.5

import { scale } from '@helpers4/geometry';
// or, from the all-in-one package (same code, one install):
import { scale } from 'helpers4/geometry';
scale(sx: number, sy: number): Matrix
ParameterTypeDescription
sxnumberHorizontal factor
synumberVertical factor, `sx` by default

Matrix — The scaling matrix

One factor scales both axes.

applyToPoint(scale(2), { x: 3, y: 4 }) // => { x: 6, y: 8 }

A negative factor mirrors the axis.

applyToPoint(scale(1, -1), { x: 3, y: 4 }) // => { x: 3, y: -4 }

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