As many of you may be aware, the flash package contains a geom.Matrix class which is useful for Linear Translations of DisplayObjects as well as BitmapData. The matrix class allows for a 3×3 array which is useful for 2D transformations such as shearing, rotation, and scaling.
Of course with any of these mentioned transformations, the origin point is always used when determining the new calculations. When dealing with offsets many people have been using the following way to adjust the origin point.
var newOriginX:uint,newOriginY:uint; newOriginX=newOriginY=16 var matrix:Matrix= new Matrix() matrix.translatePoint(newOriginX,newOriginY) matrix.rotate(45) matrix.translatePoint(-newOriginX,-newOriginY)
I prefer to use the actual properties and believe in the convenience of its setup, so I wanted to share another way since I could not find it documented online anywhere.
Both the above code and the following code produce the same effect. This is known as an Affine Transformation
var cos:Number=Math.cos(theta) var sin:Number=Math.sin(theta) var matrix:Matrix = new Matrix() matrix.a=cos;matrix.b=-sin;matrix.tx=newOriginX-newOriginX*cos-newOriginY*sin; matrix.c=sin;matrix.d=cos;matrix.ty= newOriginY+newOriginX*sin-newOriginY*cos;