MatrixMath.as
package {
import flash.display.Sprite;
import flash.geom.Matrix;
import flash.geom.Point;
/**
matrix number: a b c d tx ty
transform formulate
x2=a*x1+c*y1+tx
y2=b*x1+d*y1+ty
*/
public class MatrixMath extends Sprite
{
public function MatrixMath()
{
var m:Matrix=new Matrix();
trace("matrix just constructed: "+m); //(a=1, b=0, c=0, d=1, tx=0, ty=0)
m.translate(10,20);
trace("translate 20,20: "+m); //(1,0,0,1, 10, 20);
m.identity();//reset to identity
m.scale(2,3);
trace("scale 2,3: "+m); //(a=2, b=0, c=0, d=3, tx=0, ty=0);
m.identity();
m.rotate(30*Math.PI/180);
trace(" rotate 30: "+m); //(a=cos(30), b=sin(30), c=-sin(30), d=cos(30), tx=0, ty=0)
m.identity();
m.b=2; //shear (skew) in y axis
trace("b=2: "+m); //(a=1,b=2,c=0,d=1,tx=0, ty=0)
var p:Point=m.transformPoint(new Point(1,2));
trace("point(1,2) => : "+p); //(1,4)
}
}
}
output
scale matrix: (a=0.5, b=0, c=0, d=0.75, tx=0, ty=0)
rotation 30 degree matrix: (a=0.86602783203125, b=0.5, c=-0.5, d=0.86602783203125, tx=0, ty=0)
matrix just constructed: (a=1, b=0, c=0, d=1, tx=0, ty=0)
translate 20,20: (a=1, b=0, c=0, d=1, tx=10, ty=20)
scale 2,3: (a=2, b=0, c=0, d=3, tx=0, ty=0)
rotate 30: (a=0.8660254037844387, b=0.49999999999999994, c=-0.49999999999999994, d=0.8660254037844387, tx=0, ty=0)
b=2: (a=1, b=2, c=0, d=1, tx=0, ty=0)
point(1,2) => : (x=1, y=4)