# extracting rotation, scale values from 2d transformation matrix

how can i extract rotation, scale values from 2d transformation matrix? i mean a have a 2d transformation

matrix = [1, 0, 0, 1, 0, 0]

matrix.rotate(45 / 180 * PI)
matrix.scale(3, 4)
matrix.translate(50, 100)
matrix.rotate(30 / 180 * PI)
matrix.scale(-2, 4)
now my matrix have values [a, b, c, d, tx, ty]


lets forget about the processes above and imagine that we have only the values a, b, c, d, tx, ty

how can i find total rotation and scale values via a, b, c, d, tx, ty

sorry for my english

-

Esentially you need to solve the following

$$\left[\begin{array}{ccc} \mathrm{a} & \mathrm{b} & \mathrm{ty}\\ \mathrm{c} & \mathrm{d} & \mathrm{ty}\end{array}\right]=\left[\begin{array}{ccc} s_{x}\cos\psi & -s_{x}\sin\psi & x_{c}\\ s_{y}\sin\psi & s_{y}\cos\psi & y_{c}\end{array}\right]$$

where $s_x$, $s_y$ are the scalings, $x_c$, $y_c$ is the translation and $\psi$ is the rotation angle. The results I get are:

$$x_{c}=\mathrm{tx}$$ $$y_{c}=\mathrm{ty}$$ $$s_{x}=\mathrm{sign(a)\,}\sqrt{\mathrm{a}^{2}+\mathrm{b}^{2}}$$ $$s_{y}=\mathrm{sign(d)\,}\sqrt{\mathrm{c}^{2}+\mathrm{d}^{2}}$$ $$\tan\psi=-\frac{\mathrm{b}}{\mathrm{a}}=\frac{\mathrm{c}}{\mathrm{d}}$$

-
thank you but sx and sy will always be positive because of power 2. what about negative scale values? –  Tolgahan Albayrak Dec 5 '10 at 22:20
You can check the sign of the scalings by looking at the sign of $\mathrm{a}$ for $s_x$ and the sign of $\mathrm{d}$ for $s_y$, since the $\cos\psi$ operation is not expected to produce a negative number for $-\pi/2\leq\psi\leq\pi/2$ which is what is returned by the $\arctan$ function. –  ja72 Dec 5 '10 at 22:29
now it works.. thanks! –  Tolgahan Albayrak Dec 5 '10 at 22:41

Scale and Rotation Extraction for Action Script 3

package nid.utils
{
import flash.geom.Matrix;
import flash.geom.Point;
import nid.geom.DMatrix;
/**
* ...
* @author Nidin P Vinayakan
*/
public class MatrixConvertor
{
public static const degree:Number = 180 / Math.PI;
public static const radian:Number = Math.PI / 180;

public function MatrixConvertor()
{

}
public static function convert(mat:Matrix):DMatrix
{
var dmat:DMatrix = new DMatrix(mat.a, mat.b, mat.c, mat.d, mat.tx, mat.ty);
var deg:Number;
var sign:Number;
/**
* scaleX = √(a^2+c^2)
* scaleY = √(b^2+d^2)
* rotation = tan^-1(c/d) = tan^-1(-b/a) it will not work sometimes
* rotation = a / scaleX  = d / scaleY
*/
with (dmat)
{
scaleX = Math.sqrt((a * a) + (c * c));
scaleY = Math.sqrt((b * b) + (d * d));

sign = Math.atan(-c / a);

if (deg > 90 && sign > 0)
{
rotation = (360 - deg) * radian;
}
else if (deg 
-
Scale and Rotation Extraction for Action Script 3 Thank you for your answer,but i can't understand your answer. for example: what's meaning of the a c degree, radian and so on.... thank you! –  user19914 Nov 22 '11 at 7:33
too bad this answer is incomplete. –  bigp Aug 21 '13 at 15:41