X-Git-Url: http://source.jalview.org/gitweb/?p=jalviewjs.git;a=blobdiff_plain;f=site%2Fj2s%2Fjalview%2Fmath%2FRotatableMatrix.js;h=bec7c23fffdd5c31397d77759633e926885550e0;hp=12195cae47b34e4ae9791bddd24b07f6fdd484db;hb=b9b7a352eee79b7764c3b09c9d19663075061d8c;hpb=8ffd05b3abe52c0b6b79b011c0966361f82d5fe6 diff --git a/site/j2s/jalview/math/RotatableMatrix.js b/site/j2s/jalview/math/RotatableMatrix.js index 12195ca..bec7c23 100644 --- a/site/j2s/jalview/math/RotatableMatrix.js +++ b/site/j2s/jalview/math/RotatableMatrix.js @@ -1,114 +1,114 @@ -Clazz.declarePackage ("jalview.math"); -c$ = Clazz.decorateAsClass (function () { -this.matrix = null; -this.temp = null; -this.rot = null; -Clazz.instantialize (this, arguments); -}, jalview.math, "RotatableMatrix"); -Clazz.makeConstructor (c$, -function (rows, cols) { -this.matrix = Clazz.newFloatArray (rows, cols, 0); -this.temp = Clazz.newFloatArray (3, 0); -this.rot = Clazz.newFloatArray (3, 3, 0); -}, "~N,~N"); -Clazz.defineMethod (c$, "addElement", -function (i, j, value) { -this.matrix[i][j] = value; -}, "~N,~N,~N"); -Clazz.defineMethod (c$, "print", -function () { -System.out.println (this.matrix[0][0] + " " + this.matrix[0][1] + " " + this.matrix[0][2]); -System.out.println (this.matrix[1][0] + " " + this.matrix[1][1] + " " + this.matrix[1][2]); -System.out.println (this.matrix[2][0] + " " + this.matrix[2][1] + " " + this.matrix[2][2]); -}); -Clazz.defineMethod (c$, "rotate", -function (degrees, axis) { -var costheta = Math.cos ((degrees * 3.141592653589793) / 180.0); -var sintheta = Math.sin ((degrees * 3.141592653589793) / 180.0); -if (axis == 'z') { -this.rot[0][0] = costheta; -this.rot[0][1] = -sintheta; -this.rot[0][2] = 0.0; -this.rot[1][0] = sintheta; -this.rot[1][1] = costheta; -this.rot[1][2] = 0.0; -this.rot[2][0] = 0.0; -this.rot[2][1] = 0.0; -this.rot[2][2] = 1.0; -this.preMultiply (this.rot); -}if (axis == 'x') { -this.rot[0][0] = 1.0; -this.rot[0][1] = 0.0; -this.rot[0][2] = 0.0; -this.rot[1][0] = 0.0; -this.rot[1][1] = costheta; -this.rot[1][2] = sintheta; -this.rot[2][0] = 0.0; -this.rot[2][1] = -sintheta; -this.rot[2][2] = costheta; -this.preMultiply (this.rot); -}if (axis == 'y') { -this.rot[0][0] = costheta; -this.rot[0][1] = 0.0; -this.rot[0][2] = -sintheta; -this.rot[1][0] = 0.0; -this.rot[1][1] = 1.0; -this.rot[1][2] = 0.0; -this.rot[2][0] = sintheta; -this.rot[2][1] = 0.0; -this.rot[2][2] = costheta; -this.preMultiply (this.rot); -}}, "~N,~S"); -Clazz.defineMethod (c$, "vectorMultiply", -function (vect) { -this.temp[0] = vect[0]; -this.temp[1] = vect[1]; -this.temp[2] = vect[2]; -for (var i = 0; i < 3; i++) { -this.temp[i] = (this.matrix[i][0] * vect[0]) + (this.matrix[i][1] * vect[1]) + (this.matrix[i][2] * vect[2]); -} -vect[0] = this.temp[0]; -vect[1] = this.temp[1]; -vect[2] = this.temp[2]; -return vect; -}, "~A"); -Clazz.defineMethod (c$, "preMultiply", -function (mat) { -var tmp = Clazz.newFloatArray (3, 3, 0); -for (var i = 0; i < 3; i++) { -for (var j = 0; j < 3; j++) { -tmp[i][j] = (mat[i][0] * this.matrix[0][j]) + (mat[i][1] * this.matrix[1][j]) + (mat[i][2] * this.matrix[2][j]); -} -} -for (var i = 0; i < 3; i++) { -for (var j = 0; j < 3; j++) { -this.matrix[i][j] = tmp[i][j]; -} -} -}, "~A"); -Clazz.defineMethod (c$, "postMultiply", -function (mat) { -var tmp = Clazz.newFloatArray (3, 3, 0); -for (var i = 0; i < 3; i++) { -for (var j = 0; j < 3; j++) { -tmp[i][j] = (this.matrix[i][0] * mat[0][j]) + (this.matrix[i][1] * mat[1][j]) + (this.matrix[i][2] * mat[2][j]); -} -} -for (var i = 0; i < 3; i++) { -for (var j = 0; j < 3; j++) { -this.matrix[i][j] = tmp[i][j]; -} -} -}, "~A"); -Clazz.defineMethod (c$, "setIdentity", -function () { -this.matrix[0][0] = 1.0; -this.matrix[1][1] = 1.0; -this.matrix[2][2] = 1.0; -this.matrix[0][1] = 0.0; -this.matrix[0][2] = 0.0; -this.matrix[1][0] = 0.0; -this.matrix[1][2] = 0.0; -this.matrix[2][0] = 0.0; -this.matrix[2][1] = 0.0; -}); +Clazz.declarePackage ("jalview.math"); +c$ = Clazz.decorateAsClass (function () { +this.matrix = null; +this.temp = null; +this.rot = null; +Clazz.instantialize (this, arguments); +}, jalview.math, "RotatableMatrix"); +Clazz.makeConstructor (c$, +function (rows, cols) { +this.matrix = Clazz.newFloatArray (rows, cols, 0); +this.temp = Clazz.newFloatArray (3, 0); +this.rot = Clazz.newFloatArray (3, 3, 0); +}, "~N,~N"); +Clazz.defineMethod (c$, "addElement", +function (i, j, value) { +this.matrix[i][j] = value; +}, "~N,~N,~N"); +Clazz.defineMethod (c$, "print", +function () { +System.out.println (this.matrix[0][0] + " " + this.matrix[0][1] + " " + this.matrix[0][2]); +System.out.println (this.matrix[1][0] + " " + this.matrix[1][1] + " " + this.matrix[1][2]); +System.out.println (this.matrix[2][0] + " " + this.matrix[2][1] + " " + this.matrix[2][2]); +}); +Clazz.defineMethod (c$, "rotate", +function (degrees, axis) { +var costheta = Math.cos ((degrees * 3.141592653589793) / 180.0); +var sintheta = Math.sin ((degrees * 3.141592653589793) / 180.0); +if (axis == 'z') { +this.rot[0][0] = costheta; +this.rot[0][1] = -sintheta; +this.rot[0][2] = 0.0; +this.rot[1][0] = sintheta; +this.rot[1][1] = costheta; +this.rot[1][2] = 0.0; +this.rot[2][0] = 0.0; +this.rot[2][1] = 0.0; +this.rot[2][2] = 1.0; +this.preMultiply (this.rot); +}if (axis == 'x') { +this.rot[0][0] = 1.0; +this.rot[0][1] = 0.0; +this.rot[0][2] = 0.0; +this.rot[1][0] = 0.0; +this.rot[1][1] = costheta; +this.rot[1][2] = sintheta; +this.rot[2][0] = 0.0; +this.rot[2][1] = -sintheta; +this.rot[2][2] = costheta; +this.preMultiply (this.rot); +}if (axis == 'y') { +this.rot[0][0] = costheta; +this.rot[0][1] = 0.0; +this.rot[0][2] = -sintheta; +this.rot[1][0] = 0.0; +this.rot[1][1] = 1.0; +this.rot[1][2] = 0.0; +this.rot[2][0] = sintheta; +this.rot[2][1] = 0.0; +this.rot[2][2] = costheta; +this.preMultiply (this.rot); +}}, "~N,~S"); +Clazz.defineMethod (c$, "vectorMultiply", +function (vect) { +this.temp[0] = vect[0]; +this.temp[1] = vect[1]; +this.temp[2] = vect[2]; +for (var i = 0; i < 3; i++) { +this.temp[i] = (this.matrix[i][0] * vect[0]) + (this.matrix[i][1] * vect[1]) + (this.matrix[i][2] * vect[2]); +} +vect[0] = this.temp[0]; +vect[1] = this.temp[1]; +vect[2] = this.temp[2]; +return vect; +}, "~A"); +Clazz.defineMethod (c$, "preMultiply", +function (mat) { +var tmp = Clazz.newFloatArray (3, 3, 0); +for (var i = 0; i < 3; i++) { +for (var j = 0; j < 3; j++) { +tmp[i][j] = (mat[i][0] * this.matrix[0][j]) + (mat[i][1] * this.matrix[1][j]) + (mat[i][2] * this.matrix[2][j]); +} +} +for (var i = 0; i < 3; i++) { +for (var j = 0; j < 3; j++) { +this.matrix[i][j] = tmp[i][j]; +} +} +}, "~A"); +Clazz.defineMethod (c$, "postMultiply", +function (mat) { +var tmp = Clazz.newFloatArray (3, 3, 0); +for (var i = 0; i < 3; i++) { +for (var j = 0; j < 3; j++) { +tmp[i][j] = (this.matrix[i][0] * mat[0][j]) + (this.matrix[i][1] * mat[1][j]) + (this.matrix[i][2] * mat[2][j]); +} +} +for (var i = 0; i < 3; i++) { +for (var j = 0; j < 3; j++) { +this.matrix[i][j] = tmp[i][j]; +} +} +}, "~A"); +Clazz.defineMethod (c$, "setIdentity", +function () { +this.matrix[0][0] = 1.0; +this.matrix[1][1] = 1.0; +this.matrix[2][2] = 1.0; +this.matrix[0][1] = 0.0; +this.matrix[0][2] = 0.0; +this.matrix[1][0] = 0.0; +this.matrix[1][2] = 0.0; +this.matrix[2][0] = 0.0; +this.matrix[2][1] = 0.0; +});