# Can't work out how matrix is applied to 2D vertices

I have a texture, some 2D vertices, and a matrix. The matrix is used to calculate the texture coordinates for each vertex, but the problem is that the matrix comes with absolutely no documentation and I'm having trouble working out how to calculate the texture coords correctly. I have it partially working.

The matrix is in this format:

sx rx tx
ry sy ty


Where s means "scale", r means "rotate", and t means "translate".

If the matrix doesn't contain any rotation (i.e. ry = rx = 0), I can correctly calculate the texture coordinates u and v like this:

u = x/sx - tx
v = y/sy - ty


But I can't figure out how to put rx and ry into the equation and get the correct results. Normal matrix multiplication involves multiplying and adding but this one involves dividing and subtracting, so I know I'm missing something but I don't know what it is.

Here is one of the matrices with rotation:

26.191574096679688   7.0180206298828125  1579
-7.0180206298828125  26.191574096679688  1879


Here is one of the matrices without rotation:

27.115478515625  0                1867
0                27.115478515625  800

• For 2D coordinates with rotations you need a 3x3 matrix, not a 3x2 matrix. So where's the last part? :) Aug 25, 2012 at 9:29
• It's assumed to be 0, 0, 1 I guess. Aug 25, 2012 at 9:30
• Plus, rotation only requires a 2x2 matrix. Translation requires a 3x3 matrix. Aug 25, 2012 at 9:37
• It is x*sx not x/sx, and it is +tx*1 not -tx*1 you might want to lookup matrix vector multiplication on wikipedia Aug 25, 2012 at 9:47
• @Maik that gives incorrect results. It's not a straight matrix multiplication. Please read the question before commenting. Aug 25, 2012 at 9:53

As analyzed in the comments, the matrix was the inverse matrix. Inverting it gives the correct results. Here is the first example from the question:

scale = 27.115515  rot = -15 deg   trans = {1579, 1879}

26.191574096679688   7.0180206298828125  1579
-7.0180206298828125  26.191574096679688  1879


the inverse matrix to use is:

0.0356226228  -0.0095450654   -38.3129425048
0.0095450654   0.0356226228   -82.0065689086