Quantunet.com

My Account

Joins Us
Flash 8 Actionscript 2.0 Knowledgebase
Matrix Reflection Knowledgebase  

Coordinate Reflection Using Matrices
As we have seen in matrix multiplication any* matrix when multiplied by the unit matrix remains unchanged.

The Unit Matrix

unitmatrix


xyz unit matrix

The unit matrix can be modified to change the resulting matrix in predictable way. Each non zero term in the unit matrix acts on a single specific column of elements in the matrix it is multiplied with. This can be very usefull if you wish to perform a transformation on a sepcific set of data within a matrix. For example if you create a matrix with the x,y,z coordinates of a point in 3D and then multiply it with this modified unit matrix:

y axis reflection

The resulting matrix is identicle accept for the fact that the value of the x coordinate is now negative.

unitmatrix reflection
This has the effect of reflecting that point on the y axis. Modifying other values in the unit matrix can create reflection about other axis:

Reflection about the x axis

relection about x axis

Resulting in the value of the y coordinate becoming negative.

x axis reflection matrix multiplication

To learn more about matrices see:

[Matrix Knowledgebase]
[Adding Matricies]

[Subtracting Matricies]
[Multiplying A Matrix By A Scalar]


*Note
: This is true only if the matrix meets the basic condition that the number of columns of the first matrix match the number of rows of the unit matrix.

Reflection Using Matrices In Actionscript
(movie clip)

Note:
There is no explicit reflection transformation matrix in actionscript 2.0. However you make a set of points or a movie clip reflect by simply setting the scale values of sx and sy to negative 1.

import flash.geom.Matrix;

my_mc.transform.matrix = new Matrix(-1,0,0,0,-1,0,0,0,1);

Becasue there is no exclusive matrix transformation matrix there in no exclusive method available for reflection. However the scale method can also be used to reflect a set of points or a movie clip on the x or y axis by setting the scale x or scale y values to negative 1.

import flash.geom.Matrix;
var xscale:Number = -1;
var yscale:Number = -1;

my_matrix = new Matrix()
my_mc.my_matrix.scale(xscale,yscale);

Reflection Using Matrices In Actionscript (points)

var xscale = -1;
var yscale = -1;

my_point_matrix = new Array (20,150, 80,60, 95,130, 220,110);
xy_ref_matrix = new Array (xscale,0, 0,yscale);

matrix_mult (my_point_matrix, xy_ref_matrix);


matrix_mult (matrixA:Array, martrixB:Array):Array {
var result_coords:Array = new Array();

result_coords[0] = matrixA[0]*martrixB[0] + matrixA[1]*martrixB[3];
result_coords[1] = matrixA[0]*martrixB[1] + matrixA[1]*martrixB[4];

result_coords[2] = matrixA[2]*martrixB[0] + matrixA[3]*martrixB[3];
result_coords[3] = matrixA[2]*martrixB[1] + matrixA[3]*martrixB[4];

result_coords[4] = matrixA[4]*martrixB[0] + matrixA[5]*martrixB[3];
result_coords[5] = matrixA[4]*martrixB[1] + matrixA[5]*martrixB[4];

result_coords[6] = matrixA[6]*martrixB[0] + matrixA[7]*martrixB[3];
result_coords[7] = matrixA[6]*martrixB[1] + matrixA[7]*martrixB[4];

return result_coords;
}

To learn how to reflect points in 3d see: [3D Matrix Reflection Knowledgebase].


© 2008 Quantunet LLC All Rights Reserved | Intellectual Property | Terms of Use | Privacy
Home | About Quantunet | FAQ's | Contact Us