Lo primero, muchas gracias por mandarnos esto :)
Si pudieras mandarnos algo de codigo de como se usa vendr�a bastante bien.
He estado mirandolo y hay algunas cosas que no he conseguido comprender:
1-�Como meto un valor determinado en la matriz en una posicion
determinadaal estilo de matriz[2][1]="foo"? solo he conseguido meter valores
con setRow y setCol
2-�Y sacar un valor determinado?
tambi�n he encontrado un poco de codigo que no vale para nada, cuando haces
en el metodo checkFilled()
return (countElementsCreated == this.columns*this.rows);
delete countElementsCreated;
realmente no hace falta borrar esa variable, se destruye sola cuando sale
del metodo (por lo menos eso parece mirando el debugger)
de todas maneras aunque la quisieras borrar, nunca ejecuta nada despues de
un return.
Tambi�n he a�adido 3 nuevos metodos, espero que no te importe :)
son:
dumpMatrix() que vuelca la matriz en la ventana salida, util para la
depuraci�n.
getRow y getCol para coger Arrays con la fila o columna que interese.
incluyo la clase retocada en formato .as (esque si le hago un paste aqui se
chafa un poco el asunto, y asi es mas manejable)
DDT
<% Joseba Alonso Perez %>
<% Desarrollador web %>
<% www.inproweb.com %>
----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, August 21, 2001 3:22 PM
Subject: [flashmaestro] Prototype de Matrices
> Hola a todos:
> Acabo de terminar una clase re-usable que pienso que podr�a
> interesaros. Si ten�is dudas en el uso, o quer�is a�adir o sugerir algo
> por favor no dud�is en poneros en contacto conmigo. Muchas gracias.
>
> Espero que lo disfrut�is tanto como yo haci�ndolo.
>
> M.
>
> PD.- Est� escrito en ingl�s pero no creo que sea ning�n problema.
>
> ---------------8< ------ C�digo ------------------
>
> // -------------------
> // Basic Matrix Class
> // -------------------
> // Description: It will help us in many different ways: 3D Engine,
> Particles movement, etc.
> // Author: Manuel de la Higuera ([EMAIL PROTECTED])
> // Date: 21th August 2001
> // Flash Version: 5+
>
> // Matrix constructor
> // ------------------
> //
> // usage:
> // matrixName = new Matrix (rows, columns);
> //
>
> function Matrix (rows, columns) {
> if (typeof (rows) == "number" && typeof (columns) == "number")
> this.rows = rows;
> this.columns = columns;
> }
>
>
> // matrix.clear()
> // --------------
> // Matrix.clear will make the matrix full of 0 like:
> //
> // 0 0 0
> // 0 0 0
> // 0 0 0
> //
>
> Matrix.prototype.clear = function () {
> for (var iColumns = 1; iColumns<=this.columns; ++iColumns)
> for (var iRows = 1; iRows<=this.rows; ++iRows)
> this["element" add iRows add "-" add iColumns]
> = 0;
> }
>
>
> // matrix.isSquared()
> // ------------------
> // This method will check whether matrix is squared or not.
>
> Matrix.prototype.isSquared = function () {
> return (this.rows == this.columns);
> }
>
> // matrix.makeIdentity()
> // ---------------------
> // This will make the matrix take values like the Identity. Matrix
> _must_ be an Squared one.
> //
> // Identity Matrix:
> // 1 0 0
> // M (r,r)= 0 1 0
> // 0 0 1
> //
>
> Matrix.prototype.makeIdentity = function () {
> if (matrix.isSquared())
> for (var iColumns = 1; iColumns<=this.columns;
> ++iColumns)
> for (var iRows = 1; iRows<=this.rows; ++iRows)
> if (iRows == iColumns) this["element" add iRows
> add "-" add iColumns] = 1;
> else {
> this["element" add iRows add "-" add
> iColumns] = 0;
> }
> }
>
> // matrix.checkFilled()
> // --------------------
> // Will check whether our matrix is correctly filled (all its elements)
> or not.
>
> Matrix.prototype.checkFilled = function () {
> var countElementsCreated = 0;
> for (name in this)
> if (name.indexOf("element")==0) countElementsCreated++;
> return (countElementsCreated == this.columns*this.rows);
> delete countElementsCreated;
> }
>
>
> // matrix.setRow(arguments)
> // ------------------------
> // This will set the row defined by the first argument.
>
> Matrix.prototype.setRow = function () {
> if (arguments.length - 1 <= this.columns && arguments[0] <=
> this.columns)
> for (var iArgs=1; iArgs < arguments.length; iArgs++)
> if (typeof(arguments[iArgs]) == "number")
> accept = true;
> else{
> accept = false;
> break;
> }
> if (accept)
> for (var iColumns = 1; iColumns <= arguments.length-1;
> iColumns++) {
> this["element" add arguments[0] add "-"
> add iColumns] = arguments[iColumns];
> }
> for (var iColumns = arguments.length; iColumns <=
> this.columns; iColumns++) {
> this["element" add arguments[0] add "-"
> add iColumns] = 0;
> }
> }
>
>
> // matrix.setColumn(arguments)
> // ---------------------------
> // This will set the column defined by the first argument.
>
> Matrix.prototype.setColumn = function () {
> if (arguments.length - 1 <= this.rows && arguments[0] <=
> this.rows)
> for (var iArgs=1; iArgs < arguments.length; iArgs++)
> if (typeof(arguments[iArgs]) == "number")
> accept = true;
> else{
> accept = false;
> break;
> }
> if (accept)
> for (var iRows = 1; iRows <= arguments.length-1;
> iRows++) {
> this["element" add iRows add "-" add arguments
> [0]] = arguments[iRows];
> }
> for (var iRows = arguments.length; iRows <= this.rows;
> iRows++) {
> this["element" add iRows add "-" add arguments
> [0]] = 0;
> }
> }
>
> // matrix.makeTranspose()
> // ----------------------
> // It constructs an object called "transpose" into the matrix object
> with the Transposed Matrix.
>
> Matrix.prototype.makeTranspose = function () {
> if (this.checkFilled())
> this.transpose = new Matrix(this.columns, this.rows);
> for (var iColumns = 1;
> iColumns<=this.transpose.columns; ++iColumns)
> for (var iRows = 1; iRows<=this.transpose.rows;
> ++iRows)
> this.transpose["element" add iRows
> add "-" add iColumns] = this["element" add (iColumns) add "-" add
> (iRows)];
> }
>
>
> // matrix.plusNumber(scalar)
> // -------------------------
> // This method will add an scalar to the matrix
>
> Matrix.prototype.plusNumber = function (scalar) {
> if (typeof(scalar) == "number")
> for (var iColumns = 1; iColumns<=this.columns;
> ++iColumns)
> for (var iRows = 1; iRows<=this.rows; ++iRows)
> this["element" add iRows add "-" add
> iColumns] += scalar;
> }
>
>
> // matrix.multNumber(scalar)
> // -------------------------
> // This method will multiplicate an scalar to the matrix
>
> Matrix.prototype.multNumber = function (scalar) {
> if (typeof(scalar) == "number")
> for (var iColumns = 1; iColumns<=this.columns;
> ++iColumns)
> for (var iRows = 1; iRows<=this.rows; ++iRows)
> this["element" add iRows add "-" add
> iColumns] *= scalar;
> }
>
>
> // matrix.plusMatrix(matrix, resultant)
> // -------------------
> // Sum between Matrices
>
> Matrix.prototype.plusMatrix = function (matrix, resultant) {
> if (this.columns == matrix.columns && this.rows == matrix.rows
> && this.checkFilled() && matrix.checkFilled() && typeof(resultant)
> == "string" && typeof(_root[resultant]) != "object")
> _root[resultant] = new _root.Matrix
> (this.columns,this.rows);
> for (var iColumns = 1; iColumns<=this.columns;
> ++iColumns)
> for (var iRows = 1; iRows<=this.rows; ++iRows)
> _root[resultant]["element" add iRows
> add "-" add iColumns] = this["element" add iRows add "-" add iColumns]
> +matrix["element" add iRows add "-" add iColumns];
> }
>
> // matrix.multMatrix(matrix, resultant)
> // ------------------------------------
> // Matrices multiplication
>
> Matrix.prototype.multMatrix = function (matrix, resultant) {
> if (this.rows == matrix.columns && this.checkFilled() &&
> matrix.checkFilled() && typeof(resultant) == "string")
> _root[resultant] = new _root.Matrix(this.rows,
> matrix.columns);
> for (var iRows = 1; iRows<=matrix.columns; ++iRows) {
> for (var iColumns = 1; iColumns<=this.rows;
> ++iColumns) {
> for (var iElements = 1; iElements <=
> this.columns; iElements++) {
> sum += Number(this["element"
> add iRows add "-" add iElements] * matrix["element" add iElements add "-
> " add iColumns]);
> trace(sum);
> }
> _root[resultant]["element" add iRows
> add "-" add iColumns] = sum;
> delete sum;
> }
> }
> }
>
>
matrix_class.as