# matrix scaling

This topic is 4599 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Let's say you have a matrix that does rotation, translation, and scaling. Does anyone know an easy way to determine the scaling components of the matrix? If the scaling is the same for x, y, and z, I realize you can multiply a vector such as (1, 0, 0) by it and then compute the distance from 0. However, I'd like something more elegant that works for nonuniform scaling. Mike C. http://www.coolgroups.com/zoomer

##### Share on other sites
I didnt try this yet, but it might work.

Usually, you specify a scaling matrix like this:
x 0 0 00 y 0 00 0 z 00 0 0 1

X being the X scale factor, respectively.

Lets just think of some random example matrix...
0 1 3 13 2 3 11 0 2 11 1 1 1

This matrix will scale:
0 on the x axis
2 on the y axis
2 on the z axis

Hope that helps.

##### Share on other sites
That's not right because the rotation data overlaps the scaling data.

Mike C.
http://www.coolgroups.com/zoomer

##### Share on other sites
Quote:
 Let's say you have a matrix that does rotation, translation, and scaling. Does anyone know an easy way to determine the scaling components of the matrix?
Assuming that you apply the transformations in the order S->R->T, the matrix multiplication (using column vectors) is T*R*S. The translation is independent of the linear transform, so we can just look at R*S (in 2d for simplicity):

[xx yx][sx 0 ] =
[xy yy][0 sy]

[sx*xx sy*yx]
[sx*xy sy*yy]

As you can see, the x and y basis vectors are scaled by sx and sy, respectively. Since the basis vectors are initially unit-length, their lengths are now sx and sy. Therefore:

sx = length(x_axis);
sy = length(y_axis);

Where the x and y axes are the columns or the rows of the upper-left 3x3 portion of the 4x4 matrix. You can also use this information to construct an efficient inversion, in which case you only need the squared lengths and no square roots are required.

Let me know if you need any clarification. (I think I got all that right, but you should work through it yourself to make sure...)

##### Share on other sites
I'm not quite following. You said to do:

sx = length(x_axis);

How is this length function going to work?

Thanks.

Mike C.
http://www.coolgroups.com/zoomer

##### Share on other sites
Quote:
 I'm not quite following. You said to do:sx = length(x_axis);How is this length function going to work?
Just the Pythagorean theorem. For example, the length of the x axis (and therefore the x scale factor) using row vectors would be:

sx = sqrt(m11*m11+m12*m12+m13*m13)

##### Share on other sites
Okay, I think I get it. Just to confirm.

x scaling = distancebetween(Matrix*Vector(0, 0, 0),Matrix*Vector(1, 0, 0))
y scaling = distancebetween(Matrix*Vector(0, 0, 0),Matrix*Vector(0, 1, 0))
z scaling = distancebetween(Matrix*Vector(0, 0, 0),Matrix*Vector(0, 0, 1))

And, you can just look at certain elements in the matrix to simplify some of this.

Mike C.
http://www.coolgroups.com/zoomer

##### Share on other sites
Quote:
 Okay, I think I get it. Just to confirm.x scaling = distancebetween(Matrix*Vector(0, 0, 0),Matrix*Vector(1, 0, 0))y scaling = distancebetween(Matrix*Vector(0, 0, 0),Matrix*Vector(0, 1, 0))z scaling = distancebetween(Matrix*Vector(0, 0, 0),Matrix*Vector(0, 0, 1))And, you can just look at certain elements in the matrix to simplify some of this.
That looks right (for column vectors). And as you noted, there's a lot of redundancy there - all you really need to do is calculate the length of the matrix columns themselves.