1

How, if I have a CSS3 Transform Matrix, can I invert this matrix?

E.g. if I had this matrix for rotating 45 degrees and translating 10px, 10px

matrix(0.7071067811865475, 0.7071067811865476, -0.7071067811865476, 0.7071067811865475, -0.0000000000000008881784197001252, 14.142135623730951)

how can I calculate the inverse

matrix(0.7071067811865475, -0.7071067811865476, 0.7071067811865476, 0.7071067811865475, -14.142135623730951, 0.0000000000000008881784197001252)

for rotating -45 degrees and translate -10px, -10px? Is it always simply swapping the second and third argument and swapping the fifth and sixth element (while doing *-1)?

1 Answer 1

1

No it is not. In both cases (direct and inverse) dx & dy are applied after (or before... but always in the same order) rotation/scale. One need to find an inverse matrix for the following one:

| a11 a12 dx |
| a21 a22 dy |
|  0   0  1  |

And discard the third row of the result.

In case, you only have the rotation and no scaling, inverse matrix would be something like

| a11 a21 a11*x+a21*y |
| a12 a22 a12*x+a22*y |
Sign up to request clarification or add additional context in comments.

5 Comments

So how would I go about inverting that matrix? Which elements should be swapped with which? I don't know much about matrices and am looking for a quick fix if possible :-)
I had found these functions, but they appear quite complicated. I hoped there would be a simple swap (like I assumed) or some other easy function that I could apply. Do you know of any JS functions that inverse a 3x3 matrix?
So I found sylvester.jcoglan.com/api/matrix.html#inverse which seems to do the trick. I will try this out, and if it works, accept your answer.
It took some fiddling, but it works now! I can inverse CSS3 Matrix functions. Woo :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.