Skip to content

Instantly share code, notes, and snippets.

@malko
Created September 24, 2024 08:14
Show Gist options
  • Save malko/b50165267283fcd435cd67903c42771c to your computer and use it in GitHub Desktop.
Save malko/b50165267283fcd435cd67903c42771c to your computer and use it in GitHub Desktop.
matrix transform apply
/** @typedef {[number,number,number,number,number,number]} Matrix*/
const transformApply = (/**@type {Matrix} */matrix, point=[0,0]) => {
// extract the transformation matrix values
const [scaleX, skewY, skewX, scaleY, translateX, translateY] = matrix
const [x, y] = point
// apply the transformation matrix to the point
return [
x * scaleX + y * skewX + translateX,
x * skewY + y * scaleY + translateY
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment