Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I have a $2\times 3$ affine matrix $$ M = \pmatrix{a &b &c\\ d &e &f} $$ which transforms a point $(x,y)$ into $x' = a x + by + c, y' = d x + e y + f$

Is there a way to decompose such matrix into shear, rotation, translation,and scale ? I know there's something for $4\times 4$ matrixes, but for a $2\times 3$ matrix ?

share|improve this question
You can use the natural embedding of your 2x3 matrices in 4x4 matrices and apply the algorithms you know. –  Listing Nov 2 '11 at 10:02
What's "natural embedding" ? Sorry if it's something trivial, but I'm not a mathematician. I was also thinking that ideally the affine transform should be something like M = A * p + T, where T is the translation vector simply given by c and f. So maybe I should "simply" decompose A (a 2x2 matrix) ? –  Alfio Castorina Nov 2 '11 at 10:38
add comment

2 Answers 2

You've written this somewhat unorthodoxly. To use that matrix for that transformation, one would more usually write


So the difference between a $2\times3$ matrix and a $4\times4$ matrix was only from your way of writing it; this works the same way as an affine transform in three dimensions, just with one fewer dimension. You can immediately factor out the translation,


Then you just have to decompose $\pmatrix{a&b\\d&e}$ into shear, rotation and scaling in two dimensions.

[Edit in response to the comment:]

This isn't a unique decomposition, since you can do the shear, rotation and scaling in any order. Here's the decomposition I use:



$$ \begin{eqnarray} p&=&\sqrt{a^2+b^2}\;,\\ r&=&\frac{\det A}p=\frac{ae-bd}{\sqrt{a^2+b^2}}\;,\\ q&=&\frac{ad+be}{\det A}=\frac{ad+be}{ae-bd}\;,\\ \phi&=&\operatorname{atan}(b,a)\;, \end{eqnarray} $$

where $\operatorname{atan}$ is the two-argument arctangent function with operand order as in Java. This of course assumes $p\ne0$.

share|improve this answer
Thanks to both for the complete decomposition –  Alfio Castorina Nov 2 '11 at 15:00
add comment

If $(x, y, 1)$ is a vector in homogeneous coordinates, we have, by decomposing $M$ into blocks, that

$$M \left[\begin{array}{c}x\\y\\1\end{array}\right] = \left[\begin{array}{cc} a& b\\ d&e\end{array}\right]\left[\begin{array}{c}x\\y\end{array}\right] + \left[\begin{array}{c}c\\f\end{array}\right].$$

Here $(c,f)$ is the translation component. We can decompose the 2x2 matrix into a composition of a rotation, shear, and scale by using the QR decomposition:

$$\begin{align*}\left[\begin{array}{cc}a & b\\d & e\end{array}\right] &= \left[\begin{array}{cc} \cos \theta &-\sin \theta \\ \sin\theta &\cos \theta\end{array}\right]\left[\begin{array}{cc} \sqrt{a^2+d^2} & b\cos \theta + e\sin \theta\\0 & e\cos \theta - b\sin \theta\end{array}\right]\\ &=\left[\begin{array}{cc} \cos \theta &-\sin \theta \\ \sin\theta &\cos \theta\end{array}\right]\left[\begin{array}{cc}1 & \frac{b\cos \theta + e\sin\theta}{e\cos \theta-b\sin\theta}\\0 & 1\end{array}\right]\left[\begin{array}{cc}\sqrt{a^2+d^2} & 0\\0 & e\cos\theta - b\sin\theta\end{array}\right],\end{align*}$$ where $\theta = \arctan\left(\frac{d}{a}\right).$

share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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