# Computing angle of rotation and scaling factor directly from given transformation matrix

I have a simple 2D transformation matrix performing rotation combined with scaling \begin{bmatrix} 1 & 1 \\ -1 & 1 \end{bmatrix} Where the scalar $r$ is multiplied with \begin{bmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{bmatrix} Is there a simple method that can be performed on the input matrix to compute $r$ and $\theta$ directly?

An alternative to Henrik's version, perhaps more easily understandable is the use of

{Q, R} = QRDecomposition[{{1, 1}, {-1, 1}}]
(* {{{1/Sqrt, -(1/Sqrt)}, {1/Sqrt, 1/Sqrt}}, {{Sqrt,0}, {0, Sqrt}}} *)


Q is a rotation matrix and R contains the scaling

Solve[RotationMatrix[\[CurlyPhi] ] == Q, \[CurlyPhi]][] /.C -> 0
(*{\[CurlyPhi] -> \[Pi]/4} *)

• Very good, indeed. – Henrik Schumacher May 25 '18 at 12:26
• @Henrik: Thanks, what is needed for the direct solution is the the polar decomposition of a matrix, but I didn't find a Mathematica implementation... – Ulrich Neumann May 25 '18 at 12:47
• I could not find it either. =/ – Henrik Schumacher May 25 '18 at 12:48
• @Henrik: For "regular" matrix M one could take S = MatrixPower[Transpose[M].M, 1/2]; R = Inverse[Transpose[M]].S(* rotationmatrix R^t.R=Identity*) with polar decomposition M=R.S – Ulrich Neumann May 25 '18 at 12:53

You may try to apply this function:

{#[[2, 1, 1]], -ArcTan @@ (#[].#[])[]} &[SingularValueDecomposition[#]] &


A bit simpler, using complex numbers:

f = AbsArg[({1, I}.#)[]] &
f[{{1, 1}, {-1, 1}}]


$\left\{\sqrt{2},-\frac{\pi }{4}\right\}$

General case:

A random scale-rotation:

scale = If[Variance[Diagonal[S]] < $MachinePrecision^2, Mean[Diagonal[S]],$Failed
]


First we compute the polar decomposition of M

{U, Σ, V} = SingularValueDecomposition[M];
R = U.Transpose[V];
S = V.Σ.Transpose[V];


Checking its validity:

Norm[R.S - M, "Frobenius"]
Norm[Transpose[R].R - IdentityMatrix[dim], "Frobenius"]
Norm[S - Transpose[S], "Frobenius"]


2.01949*10^-15

6.36666*10^-16

7.11972*10^-16

Everything seems to be good. R is the rotation matrix we are looking for. If S is a mupltiple of the identy matrix then this multiple is the scaling factor. Otherwise, we have non-uniform scalings.

scale = If[
Norm[Mean[Diagonal[S]] IdentityMatrix[dim] - S,
"Frobenius"] < $MachinePrecision^2, Mean[Diagonal[S]],$Failed
]

m = {{1, 1}, {-1, 1}};
FullSimplify @ Solve[ConjugateTranspose[RotationMatrix[θ]].ScalingMatrix[{s1, s2}] == m,
{s1, s2, θ}, Reals] /. C -> 0 // TeXForm


$\left\{\left\{\text{s1}\to -\sqrt{2},\text{s2}\to -\sqrt{2},\theta \to -\frac{3 \pi }{4}\right\},\left\{\text{s1}\to \sqrt{2},\text{s2}\to \sqrt{2},\theta \to \frac{\pi }{4}\right\}\right\}$