Tuesday, March 13, 2007

Matrix Transformation

Matrix takes three points as parameters, first point is the origin, the second point being the X-axis and third point marks the Y-axis. Changing the order of points changes the orientation of the XY-axis. The Transform function of Graphics associates the Matrix to the graphics object. The newly drawn graph objects would have the new orientation. The TranslateTransform function of Graphics object moves the origin to the new point that is passed as parameter to TranslateTransform.
 
private PointF[] pArray;

Matrix m;

Graphics g;

//Rectangle must be declared before usage.

//pArray is initialized here.

m = new Matrix(Rectangle, pArray);

g.Transform = m;


pArray = new PointF[] { new PointF(this.Width, this.Height), new PointF(0, 0), new PointF(0, this.Height) };

X diagonal
Y horizontal


pArray = new PointF[] { new PointF(0, this.Height), new PointF(this.Width, this.Height), new PointF(0, 0) };

X horizontal
Y vertical


pArray = new PointF[] { new PointF(this.Width, this.Height), new PointF(0, this.Height), new PointF(0, 0) };

X horizontal
Y diagonal


pArray = new PointF[] { new PointF(0, 0), new PointF(0, this.Height), new PointF(this.Width, this.Height) };

X vertical
Y diagonal


pArray = new PointF[] { new PointF(0, 0), new PointF(this.Width, this.Height), new PointF(0, this.Height) };

X diagonal
Y vertical


pArray = new PointF[] { new PointF(0, this.Height), new PointF(0, 0), new PointF(this.Width, this.Height) };

X horizontal
Y vertical

No comments: