# Un-scaling the matrix - how?

1. Dec 26, 2007

### makc

1. The problem statement, all variables and given/known data
We have (3d) vectors v1 and v2, and some matrix M, v2 = M v1. This scales and rotates vectors, but I need to constrain this to rotation only. So we have this in a form M = S * R (or R * S) where S is scaling only matrix, and R is rotation only.

2. Relevant equations
If I knew these, I wouldn't be posting.

3. The attempt at a solution
I figured that S must be diagonal matrix, and if we put ort vectors through M, we could somehow find its non-zero coefs and then easily invert it, but the exact math escapes me... Then I thought, there must be someone who did this, or knows someone who did :)

 I have found this unfinished discussion on gamedev, that suggests this thing is implemented in directx, so it is definitely possible; meanwhile, I will keep searching.

 holy crrr carramba, it seems so complex. 1 + 2 and 3... my head is going to explode.

is there at least any simple way to extract rotation part alone?

Last edited: Dec 26, 2007
2. Dec 27, 2007

### NateTG

I'm not sure that such a decomposition exists in the general case.

You should look into the QR decomposition algorithms.

3. Dec 28, 2007

### makc

hey thanks I looked at this method, and it seems to solve my problem in just three steps. however, I do not understand whre they got 6 in denominator from.

I also looked at this article, and the notes there seem to be saying that I can compute G coefs immediately, without finding an angle. but there I cant seem to grasp where do they get a and b from.

:(

4. Dec 28, 2007

### D H

Staff Emeritus
There's always Numerical Recipes, http://www.nrbook.com/a/bookcpdf/c2-10.pdf

Beware that the code is in "C-Tran" (Fortran translated to C). In particular, arrays are indexed from 1 (ala Fortran) rather than 0, as in C.

5. Dec 29, 2007

### makc

thanks, but that pdf doesnt open here. I seem to figure that a and b refer to values in original matrix, so I will try to code this per wiki (hopefully people who wrote that did not screw it up).

Last edited: Dec 29, 2007
6. Dec 29, 2007

### Hurkyl

Staff Emeritus
Just to clarify...

S is supposed to be a diagonal matrix?
R is supposed to be an orthogonal matrix with determinant 1?

If so, this is appears to be a very easy problem:

If M = RS, then

$$M^T M = S^T R^T R S = S I S = S^2$$

If M = SR, then

$$M M^T = S R R^T S^T = S I S = S^2$$

Either way, you can cancel out the rotation and thus get the square of your scaling matrix. All that's left is to take the square root, and guess the signs.

If R is allowed to be a combination of rotations and reflections, then it doesn't even matter if you get the signs right!

If S is supposed to be a multiple of the identity, it's even easier: SR=RS, and you only need to compute a single entry of $M^T M$.

Last edited: Dec 29, 2007