Decompose Matrix
const deltaTransformPoint = (matrix, point) => {
return {
x: point.x * matrix.a + point.y * matrix.c,
y: point.x * matrix.b + point.y * matrix.d
}
}
const decomposeMatrix = matrix => {
let px = deltaTransformPoint(matrix, { x: 0, y: 1 })
let py = deltaTransformPoint(matrix, { x: 1, y: 0 })
let skewX = FROM_RADS * Math.atan2(px.y, px.x) - 90
let skewY = FROM_RADS * Math.atan2(py.y, py.x)
return {
tx: matrix.e,
ty: matrix.f,
scaleX: Math.sqrt(matrix.a * matrix.a + matrix.b * matrix.b),
scaleY: Math.sqrt(matrix.c * matrix.c + matrix.d * matrix.d),
skewX: skewX,
skewY: skewY,
rotation: skewX
}
}
Get the scale, translation, rotationa and skew values from a matrix.
Great stackoverflow answer from user dave