# transformation matrix

Im trying to translate and rotate a set of coordinates using a transformation matrix (calculated by another program) in AnyBody, but the resulting coordinates are different from what they should be.

This for eg. is the transformation matrix
a d g j
b e h k
c f i l
0 0 0 1

And this is the syntax that I used:
AnyFunTransform3DLin transformation=
{
ScaleMat = {{a,b,c},
{d,e,f},
{g,h,i}};
Offset = {j,k,l};
};

AnyRefNode transformedcoordinate = {
sRel = (.transformation({x,y,z}));
AnyDrawNode…
};

When I manually calculated the new coordinates using the same transformation matrix and plotted the new points, they were exactly where they should have been i.e. the transformation matrix is correct.

Can anyone tell me what Im doing wrong?

Hi,

I think the issue might be that your ScaleMat is actually the transpose of what it is supposed to be. AnyMat33 arranges the three vectors row-wise, so for example your first row entry would be {a,d,j} and so on. Try re-arranging the terms and it should give you the same answer.

Regards
Ananth

Hi Ananth,
I had tried that too (below), but it didn’t work either.

AnyFunTransform3DLin transformation=
{
ScaleMat = {{a,d,g},
{b,e,h},
{c,f,i}};
Offset = {j,k,l};
};

Could it be something to do with the offset or the fourth row in the transformation matrix?

Hi,

Could you please share the exact numbers you are working with? i.e your matrix, test vector, expected transformed vector and actual transformed vector?

Hi Irene,

According to the manual for AnyFunTransform3Lin:

“The linear scaling is defined by a 3 by 3 scaling matrix that is multiplied to the argument (3D geometrical vector) after adding a set of offset values.”

So it is not “y=x+b*A” as you think, but "y=(x+b)A". You can construct the transform to use the Offset=b(A^-1).

Kind regards,
Pavel

You could also avoid using the transformation and use the normal expression:

``````  AnyFloat k = {{1,0,0},{0,2,0},{0,0,3}};
AnyFloat b = {0.1, 0.3, -0.2};

AnyFloat test = {-1, 3, 4}*k+b;

``````

Pavel

Hello Pavel,

I used the AnyFloat commands and it worked perfectly.

Thank you!