class matrix {
var index:Array;
var _n:Number;
var _m:Number;
function matrix(m, n) {
_n = n;
_m = m;
index = new Array();
for (var i = 0; i<m; i++) {
index[i] = new Array(n);
for (var j = 0; j<n; j++) {
index[i][j] = 0;
}
}
}
function copy() {
var temp = new matrix(_m, _n);
for (var i = 0; i<_m; i++) {
for (var j = 0; j<_n; j++) {
temp.index[i][j] = index[i][j];
}
}
return temp;
}
function copy1() {
var temp = new matrix(4, 4);
for (var i = 0; i<_m; i++) {
temp.index[i] = this.index[i].slice();
trace(temp.index[i]);
}
return temp;
}
function copy2() {
var temp = new matrix(4, 4);
for (var i = 0; i<_m; i++) {
temp.index[i].push(this.index[i].slice());
for (var j = 0; j<4; j++) {
temp.index[i][j].shift();
}
trace(temp.index[i]);
}
return temp;
}
function identity(n) {
for (var i = 0; i<_m; i++) {
for (var j = 0; j<_n; j++) {
if (i == j) {
this.index[i][j] = n;
}
}
}
} <
function toString() {
var string = "[";
for (var i = 0; i<_m; ++i) {
for (var j = 0; j<_n; ++j) {
var temp = index[i][j];
if (j == _n-1) {
string = string.concat(temp);
if ((i+1)*(1+j)<_m*_n) {
string = string+"]\r[";
} else {
string = string+"]";
}
} else {
string = string+(temp+",");
}
}
}
return (string);
}
function reset() {
this.__proto__.constructor.apply(this, arguments);
}
function addition(b) {
var temp = new matrix(_m, _n);
for (var i = 0; i<_m; i++) {
for (var j = 0; j<_n; j++) {
temp.index[i][j] = this.index[i][j]+b.index[i][j]; }
}
return temp;
}
function substract(b) { <BR /> <BR />
var temp = new matrix(_m, _n); <BR /> <BR />
for (var i = 0; i<_m; i++) { <BR /> <BR />
for (var j = 0; j<_n; j++) { <BR /> <BR />
temp.index[i][j] = this.index[i][j]-b.index[i][j]; <BR /> <BR />
} <BR /> <BR />
} <BR /> <BR />
return temp; <BR /> <BR />
} <BR /> <BR />
function scalar(a) { <BR /> <BR />
for (var i = 0; i<_m; i++) { <BR /> <BR />
for (var j = 0; j<_n; j++) { <BR /> <BR />
this.index[i][j] = this.index[i][j]*a; <BR /> <BR />
} <BR /> <BR />
} <BR /> <BR />
} <BR /> <BR />
<BR /> <BR />
<BR /> <BR />
function transpose(){ <BR /> <BR />
var temp = new matrix(_n, _m); <BR /> <BR />
for (var i = 0; i<_n; i++) { <BR /> <BR />
for (var j = 0; j<_m; j++) { <BR /> <BR />
temp.index[i][j] = this.index[j][i]; <BR /> <BR />
} <BR /> <BR />
<BR /> <BR />
} <BR /> <BR />
return temp <BR /> <BR />
<BR /> <BR />
} <BR /> <BR />
function multiply4_1(b:matrix) { <BR /> <BR />
var temp = new matrix(1, 4); <BR /> <BR />
for (var i = 0; i<4; i++) { <BR /> <BR />
for (var j = 0; j<4; j++) { <BR /> <BR />
temp.index[0][i] += this.index[i][j]*b.index[0][j]; <BR /> <BR />
} <BR /> <BR />
} <BR /> <BR />
return temp; <BR /> <BR />
} <BR /> <BR />
function translate3d(m, dx, dy, dz) { <BR /> <BR />
this["index"][0][0] = 1; <BR /> <BR />
this["index"][1][1] = 1; <BR /> <BR />
this["index"][2][2] = 1; <BR /> <BR />
this["index"][3][3] = 1; <BR /> <BR />
this["index"][0][3] = dx; <BR /> <BR />
this["index"][1][3] = dy; <BR /> <BR />
this["index"][2][3] = dz; <BR /> <BR />
var temp = this.multiply4_1(m); <BR /> <BR />
return (temp); <BR /> <BR />
} <BR /> <BR />
function scale3d(b, dx, dy, dz) { <BR /> <BR />
this.index[0][0] = dx; <BR /> <BR />
this.index[1][1] = dy; <BR /> <BR />
this.index[2][2] = dz; <BR /> <BR />
this.index[3][3] = 1; <BR /> <BR />
var temp = this.multiply4_1(b); <BR /> <BR />
return (temp); <BR /> <BR />
} <BR /> <BR />
function dtor(theta) { <BR /> <BR />
return Math.PI*theta/180; <BR /> <BR />
} <BR /> <BR />
function rotate3d_x(b, a) { <BR /> <BR />
this.index[0][0] = 1; <BR /> <BR />
this.index[1][1] = Math.cos(dtor(a)); <BR /> <BR />
this.index[2][2] = Math.cos(dtor(a)); <BR /> <BR />
this.index[1][2] = -1*(Math.sin(dtor(a))); <BR /> <BR />
this.index[2][1] = Math.sin(dtor(a)); <BR /> <BR />
this.index[3][3] = 1; <BR /> <BR />
var temp = this.multiply4_1(b); <BR /> <BR />
return (temp); <BR /> <BR />
} <BR /> <BR />
function rotate3d_z(b, a) { <BR /> <BR />
this.index[0][0] = Math.cos(dtor(a)); <BR /> <BR />
this.index[1][1] = Math.cos(dtor(a)); <BR /> <BR />
this.index[2][2] = 1; <BR /> <BR />
this.index[0][1] = -1*(Math.sin(dtor(a))); <BR /> <BR />
this.index[1][0] = Math.sin(dtor(a)); <BR /> <BR />
this.index[3][3] = 1; <BR /> <BR />
var temp = this.multiply4_1(b); <BR /> <BR />
return (temp); <BR /> <BR />
} <BR /> <BR />
function rotate3d_y(b, a) { <BR /> <BR />
this.index[0][0] = Math.cos(dtor(a)); <BR /> <BR />
this.index[1][1] = 1; <BR /> <BR />
this.index[2][2] = Math.cos(dtor(a)); <BR /> <BR />
this.index[2][0] = -1*(Math.sin(dtor(a))); <BR /> <BR />
this.index[0][2] = Math.sin(dtor(a)); <BR /> <BR />
this.index[3][3] = 1; <BR /> <BR />
var temp = this.multiply4_1(b); <BR /> <BR />
return (temp); <BR /> <BR />
} <BR /> <BR />
} <BR /> <BR />
var index:Array;
var _n:Number;
var _m:Number;
function matrix(m, n) {
_n = n;
_m = m;
index = new Array();
for (var i = 0; i<m; i++) {
index[i] = new Array(n);
for (var j = 0; j<n; j++) {
index[i][j] = 0;
}
}
}
function copy() {
var temp = new matrix(_m, _n);
for (var i = 0; i<_m; i++) {
for (var j = 0; j<_n; j++) {
temp.index[i][j] = index[i][j];
}
}
return temp;
}
function copy1() {
var temp = new matrix(4, 4);
for (var i = 0; i<_m; i++) {
temp.index[i] = this.index[i].slice();
trace(temp.index[i]);
}
return temp;
}
function copy2() {
var temp = new matrix(4, 4);
for (var i = 0; i<_m; i++) {
temp.index[i].push(this.index[i].slice());
for (var j = 0; j<4; j++) {
temp.index[i][j].shift();
}
trace(temp.index[i]);
}
return temp;
}
function identity(n) {
for (var i = 0; i<_m; i++) {
for (var j = 0; j<_n; j++) {
if (i == j) {
this.index[i][j] = n;
}
}
}
} <
function toString() {
var string = "[";
for (var i = 0; i<_m; ++i) {
for (var j = 0; j<_n; ++j) {
var temp = index[i][j];
if (j == _n-1) {
string = string.concat(temp);
if ((i+1)*(1+j)<_m*_n) {
string = string+"]\r[";
} else {
string = string+"]";
}
} else {
string = string+(temp+",");
}
}
}
return (string);
}
function reset() {
this.__proto__.constructor.apply(this, arguments);
}
function addition(b) {
var temp = new matrix(_m, _n);
for (var i = 0; i<_m; i++) {
for (var j = 0; j<_n; j++) {
temp.index[i][j] = this.index[i][j]+b.index[i][j]; }
}
return temp;
}
function substract(b) { <BR /> <BR />
var temp = new matrix(_m, _n); <BR /> <BR />
for (var i = 0; i<_m; i++) { <BR /> <BR />
for (var j = 0; j<_n; j++) { <BR /> <BR />
temp.index[i][j] = this.index[i][j]-b.index[i][j]; <BR /> <BR />
} <BR /> <BR />
} <BR /> <BR />
return temp; <BR /> <BR />
} <BR /> <BR />
function scalar(a) { <BR /> <BR />
for (var i = 0; i<_m; i++) { <BR /> <BR />
for (var j = 0; j<_n; j++) { <BR /> <BR />
this.index[i][j] = this.index[i][j]*a; <BR /> <BR />
} <BR /> <BR />
} <BR /> <BR />
} <BR /> <BR />
<BR /> <BR />
<BR /> <BR />
function transpose(){ <BR /> <BR />
var temp = new matrix(_n, _m); <BR /> <BR />
for (var i = 0; i<_n; i++) { <BR /> <BR />
for (var j = 0; j<_m; j++) { <BR /> <BR />
temp.index[i][j] = this.index[j][i]; <BR /> <BR />
} <BR /> <BR />
<BR /> <BR />
} <BR /> <BR />
return temp <BR /> <BR />
<BR /> <BR />
} <BR /> <BR />
function multiply4_1(b:matrix) { <BR /> <BR />
var temp = new matrix(1, 4); <BR /> <BR />
for (var i = 0; i<4; i++) { <BR /> <BR />
for (var j = 0; j<4; j++) { <BR /> <BR />
temp.index[0][i] += this.index[i][j]*b.index[0][j]; <BR /> <BR />
} <BR /> <BR />
} <BR /> <BR />
return temp; <BR /> <BR />
} <BR /> <BR />
function translate3d(m, dx, dy, dz) { <BR /> <BR />
this["index"][0][0] = 1; <BR /> <BR />
this["index"][1][1] = 1; <BR /> <BR />
this["index"][2][2] = 1; <BR /> <BR />
this["index"][3][3] = 1; <BR /> <BR />
this["index"][0][3] = dx; <BR /> <BR />
this["index"][1][3] = dy; <BR /> <BR />
this["index"][2][3] = dz; <BR /> <BR />
var temp = this.multiply4_1(m); <BR /> <BR />
return (temp); <BR /> <BR />
} <BR /> <BR />
function scale3d(b, dx, dy, dz) { <BR /> <BR />
this.index[0][0] = dx; <BR /> <BR />
this.index[1][1] = dy; <BR /> <BR />
this.index[2][2] = dz; <BR /> <BR />
this.index[3][3] = 1; <BR /> <BR />
var temp = this.multiply4_1(b); <BR /> <BR />
return (temp); <BR /> <BR />
} <BR /> <BR />
function dtor(theta) { <BR /> <BR />
return Math.PI*theta/180; <BR /> <BR />
} <BR /> <BR />
function rotate3d_x(b, a) { <BR /> <BR />
this.index[0][0] = 1; <BR /> <BR />
this.index[1][1] = Math.cos(dtor(a)); <BR /> <BR />
this.index[2][2] = Math.cos(dtor(a)); <BR /> <BR />
this.index[1][2] = -1*(Math.sin(dtor(a))); <BR /> <BR />
this.index[2][1] = Math.sin(dtor(a)); <BR /> <BR />
this.index[3][3] = 1; <BR /> <BR />
var temp = this.multiply4_1(b); <BR /> <BR />
return (temp); <BR /> <BR />
} <BR /> <BR />
function rotate3d_z(b, a) { <BR /> <BR />
this.index[0][0] = Math.cos(dtor(a)); <BR /> <BR />
this.index[1][1] = Math.cos(dtor(a)); <BR /> <BR />
this.index[2][2] = 1; <BR /> <BR />
this.index[0][1] = -1*(Math.sin(dtor(a))); <BR /> <BR />
this.index[1][0] = Math.sin(dtor(a)); <BR /> <BR />
this.index[3][3] = 1; <BR /> <BR />
var temp = this.multiply4_1(b); <BR /> <BR />
return (temp); <BR /> <BR />
} <BR /> <BR />
function rotate3d_y(b, a) { <BR /> <BR />
this.index[0][0] = Math.cos(dtor(a)); <BR /> <BR />
this.index[1][1] = 1; <BR /> <BR />
this.index[2][2] = Math.cos(dtor(a)); <BR /> <BR />
this.index[2][0] = -1*(Math.sin(dtor(a))); <BR /> <BR />
this.index[0][2] = Math.sin(dtor(a)); <BR /> <BR />
this.index[3][3] = 1; <BR /> <BR />
var temp = this.multiply4_1(b); <BR /> <BR />
return (temp); <BR /> <BR />
} <BR /> <BR />
} <BR /> <BR />
