2
$\begingroup$

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?

$\endgroup$
4
$\begingroup$

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

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

Q is a rotation matrix and R contains the scaling

Solve[RotationMatrix[\[CurlyPhi] ] == Q, \[CurlyPhi]][[1]] /.C[1] -> 0 
(*{\[CurlyPhi] -> \[Pi]/4} *)
$\endgroup$
  • $\begingroup$ Very good, indeed. $\endgroup$ – Henrik Schumacher May 25 '18 at 12:26
  • $\begingroup$ @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... $\endgroup$ – Ulrich Neumann May 25 '18 at 12:47
  • $\begingroup$ I could not find it either. =/ $\endgroup$ – Henrik Schumacher May 25 '18 at 12:48
  • 1
    $\begingroup$ @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 $\endgroup$ – Ulrich Neumann May 25 '18 at 12:53
1
$\begingroup$

You may try to apply this function:

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

A bit simpler, using complex numbers:

f = AbsArg[({1, I}.#)[[1]]] &
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
  ]
$\endgroup$
0
$\begingroup$
m = {{1, 1}, {-1, 1}};
FullSimplify @ Solve[ConjugateTranspose[RotationMatrix[θ]].ScalingMatrix[{s1, s2}] == m, 
  {s1, s2, θ}, Reals] /. C[1] -> 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\}$

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.