ScaleRotationMatrix.as
package {
import flash.display.Graphics;
import flash.display.Shape;
import flash.display.Sprite;
import flash.geom.Matrix;
import flash.geom.Point;
public class ScaleRotationMatrix extends Sprite
{
public function ScaleRotationMatrix()
{
var p1:Point=new Point(10,10);
var p2:Point=new Point(100,50);
var shape1:Shape=createRect(p1, p2, 1);
addChild(shape1);
/* [sx b c sy tx ty]
(x1,y1) to (x2,y2);
x2=x1*sx+b*y1+tx;
y2=x1*c+sy*y1+ty;
*/
//scale
var shape2:Shape=createRect(p1, p2, 1);
addChild(shape2);
shape2.scaleX=0.5;
shape2.scaleY=0.75;
//[scaleX, 0, 0, scaleY, 0, 0]
trace("scale matrix: "+shape2.transform.matrix); // (a=0.5, b=0, c=0, d=0.75, tx=0, ty=0)
//rotation
var shape3:Shape=createRect(p1, p2,1);
addChild(shape3);
shape3.rotation=30; //degree, closewise
//[cos(angle), sin(angle), -sin(angle), cos(angle), 0, 0]
trace("rotation 30 degree matrix: "+shape3.transform.matrix);
//rotation 30 degree matrix: (a=0.86602783203125, b=0.5, c=-0.5, d=0.86602783203125, tx=0, ty=0)
}
public static function createRect(p1:Point, p2:Point, linewidth:int):Shape {
var shape:Shape=new Shape();
var g:Graphics=shape.graphics;
g.lineStyle(linewidth, 0x000000, 0.5);
g.drawRect(p1.x, p1.y, Math.abs(p2.x-p1.x), Math.abs(p2.y-p1.y));
return shape;
}
}
}