PDA

Click to See Complete Forum and Search --> : matrix: just a dream?



CarlaChi?
07-20-2002, 11:10 AM
Hallo!
I'ld like to know if someone of you found a way to have a matrix-like variable.
Maybe I have to build a custom object, but I'm not so good with object-oriented programming. Anyway, I could try it!
Thank you in advance
Carla

ericlin
07-20-2002, 08:07 PM
For the OOP things, it should be something like this:


_global.Matrix = function(a1, a2, b1, b2) {
this.a1 = a1;
this.b1 = b1;
this.a2 = a2;
this.b2 = b2;
this.double = function(x) {
return x*2;
};
};
y = new Matrix(1, 2, 3, 4);
trace(y.a2);
trace(y.double(y.b2));

We can add math functions for the Matrix object.

CarlaChi?
07-21-2002, 03:24 AM
Thank you Ericlin,
but this seems an array to me, not a matrix.
What I mean is to have an object whose elements can be reached by something like a[i, j], where i and j are integer indexes.
To define an object like this there should be some command like
m = new Matrix((4, 2, 7), (1, 0, 3), (5, 0, 1))
so that I have an array of arrays.
Is it possible?

ericlin
07-21-2002, 03:52 AM
Initially I thought you want to make a class of Matrix that you can rotate. I mean a matrix of 2x2 or 3x3 or 4x4;

If we need only arrays of arrays, Flash has already build-in functions to do multi-dimensional array; That is array of array; Only the syntax is slightly different from C language;

m = [[4, 2, 7],[1, 0, 3],[5, 0, 1]];

Then to access the third element of the first array will be:

m[0][2]; That will be 7; In C, the syntax might be m[0,2];

CarlaChi?
07-21-2002, 04:32 AM
I love it!
Thank you for providing me the right sintax.
Carla