How to revert the scale of a matrix?

Started by
3 comments, last by Ashaman73 8 years, 8 months ago

Hi there,

i have a 3x3 matrix which have a translation and a scale (rotation does not matter).

Both are coherent which means, changing the translation or scale alone wont work.

Now i have the case where i have a 3x3 matrix which has a translation and a scale which is not "identity".

How do i reset the scale to 1 but convert back the translation into the same space - so the translation is not identity, but the scale is.

Thanks,

Final

Advertisement

It depends. In general you cannot reconstruct the history how the one available matrix was generated from the matrix alone. You can just decompose the matrix into an equivalent translational and scaling transform (letting rotation aside as mentioned in the OP), replacing the transform of interest with its desired substitute, and re-compose, so that the translational part is not effected. But if the composition was done so that the position was effected by a scaling (as e.g. in S1 * T * S2), then you cannot eliminate scaling totally (AFAIK).

So in your case decomposition is relatively easy, because in a homogeneous 3x3 matrix without rotation there is an embedded 2x2 matrix that is effected by scaling only but not by translation. You get this sub-matrix if you strip the row and the column where in the 3x3 matrix the homogenous "1" is located. The resulting sub-matrix must be a diagonal matrix, e.g. only the values at [0][0] and [1][1] differ from zero. Those both values are in fact the scaling factors along x and y axis directions, resp. Hence setting both these values to 1 will do the trick.

It depends. In general you cannot reconstruct the history how the one available matrix was generated from the matrix alone. You can just decompose the matrix into an equivalent translational and scaling transform (letting rotation aside as mentioned in the OP), replacing the transform of interest with its desired substitute, and re-compose, so that the translational part is not effected. But if the composition was done so that the position was effected by a scaling (as e.g. in S1 * T * S2), then you cannot eliminate scaling totally (AFAIK).

So in your case decomposition is relatively easy, because in a homogeneous 3x3 matrix without rotation there is an embedded 2x2 matrix that is effected by scaling only but not by translation. You get this sub-matrix if you strip the row and the column where in the 3x3 matrix the homogenous "1" is located. The resulting sub-matrix must be a diagonal matrix, e.g. only the values at [0][0] and [1][1] differ from zero. Those both values are in fact the scaling factors along x and y axis directions, resp. Hence setting both these values to 1 will do the trick.

I already decompose the matrix like this:


sx = transform.m[0 * 3 + 0];
sy = transform.m[1 * 3 + 1];
tx = transform.m[0 * 3 + 2];
ty = transform.m[1 * 3 + 2];

And use this to transform my position/vertices manually:


posX = pos.x * sx + tx;
posY = pos.y * sy + ty;

The inverse matrix wont help me at all, isnt it?


How do i reset the scale to 1 but convert back the translation into the same space - so the translation is not identity, but the scale is.

Wait a moment … do you want

(a) to manipulate the transform matrix so that its scaling part is identity, or else

(b) to rescale the object's mesh in place, so it isn't moved further but has the original size?

Before I assumed you meant (a), but now your 2nd post let me think that you may alter the object's mesh directly, as for a static mesh, and want to undo part of it.

If (a) is the case then you simply need to set the transform.m[0] and transform.m[4] to 1.

If (b) is the case then you need to transfer the object temporarily into the space where the center of scaling is at the space's origin, because scaling ever extrudes from (0,0). Because the original center of scaling was at (0,0) before the translation has happened, the math would look like (following your non-matrix formulas above)


newX = ( posX - tx ) / sx + tx;
newY = ( posY - ty ) / sy + ty;

If you are used to use column vectors, then the above transform is equivalent to

p' := T * S-1 * T-1 * p

where S denotes the decomposed scaling and T the decomposed translation matrix.


How do i reset the scale to 1 but convert back the translation into the same space - so the translation is not identity, but the scale is.

Maybe this (as long as there's no rotation):

tx' = tx*sx;
ty' = ty*sy;

sx = 1;

sy = 1;

This topic is closed to new replies.

Advertisement