TITLE: Decomposing an Affine transformation
QUESTION [20 upvotes]: An affine transformation is composed of rotations, translations, scaling and shearing.
In 2D, such a transformation can be represented using an augmented matrix by 
$$
\begin{bmatrix} \vec{y} \\ 1 \end{bmatrix} =\begin{bmatrix} A & \vec{b} \ \\ 0, \ldots, 0 & 1 \end{bmatrix} \begin{bmatrix} \vec{x} \\ 1 \end{bmatrix}
$$
vector b represents the translation. Bu how can I decompose A into rotation, scaling and shearing?
I am trying to "interpolate" an affine transform so that, if I have points in a frame 1 and in a frame 3 such that a transform $T$ takes points from frame 1 to points in frame 3, then the interpolated transform would take my points from frame 1 to frame 2. If, for example, an 60° rotation is needed to go from frame 1 to frame 3, then a 30° one would be used to go from frame 1 to frame 2.
Thank you for your help.

REPLY [5 votes]: The answer provided by @John is not correct. It is not true that $\frac{A_{12} + A_{21}}{A_{11}} = \frac{A_{22} - A_{11}}{A_{21}}$ in general.
Start with 
$$
\begin{bmatrix} A_{11} & A_{12} \ \\ A_{21} & A_{22} \end{bmatrix} =  \begin{bmatrix} \cos \theta & -\sin \theta \\ \sin \theta & \cos \theta \end{bmatrix} \begin{bmatrix} 1 & m \\ 0 & 1 \end{bmatrix} \begin{bmatrix} s_x & 0 \\ 0 & s_y \end{bmatrix}.
$$
This gives
$$
\begin{align*}
   A_{11} &= s_x \cos \theta\\
   A_{12} &= s_y m \cos \theta - s_y \sin \theta\\
   A_{21} &= s_x \sin \theta\\
   A_{22} &= s_y m \sin \theta + s_y \cos \theta\\
\end{align*}
$$
From the first and third equalities, one gets 
$$
s_x = \sqrt{A_{11}^2 + A_{21}^2}
$$
and
$$
\theta = \tan^{-1}\left( \frac{A_{21}}{A_{11}} \right).
$$
From the second and fourth equalities, one gets
$$
m s_y = A_{12}\cos\theta + A_{22}\sin\theta.
$$
So we have $m s_y$.
If $\sin\theta \neq 0$, we get $s_y$ by
$$
s_y = \frac{m s_y\cos\theta - A_{12}}{\sin\theta},
$$
otherwise we can get it by
$$
s_y = \frac{A_{22} - m s_y\sin\theta}{\cos\theta}.
$$
And we finally get $m$ by $m = \dfrac{m s_y}{s_y}$.