1 Clazz.declarePackage ("jalview.math");
2 c$ = Clazz.decorateAsClass (function () {
6 Clazz.instantialize (this, arguments);
7 }, jalview.math, "RotatableMatrix");
8 Clazz.makeConstructor (c$,
9 function (rows, cols) {
10 this.matrix = Clazz.newFloatArray (rows, cols, 0);
11 this.temp = Clazz.newFloatArray (3, 0);
12 this.rot = Clazz.newFloatArray (3, 3, 0);
14 Clazz.defineMethod (c$, "addElement",
15 function (i, j, value) {
16 this.matrix[i][j] = value;
18 Clazz.defineMethod (c$, "print",
20 System.out.println (this.matrix[0][0] + " " + this.matrix[0][1] + " " + this.matrix[0][2]);
21 System.out.println (this.matrix[1][0] + " " + this.matrix[1][1] + " " + this.matrix[1][2]);
22 System.out.println (this.matrix[2][0] + " " + this.matrix[2][1] + " " + this.matrix[2][2]);
24 Clazz.defineMethod (c$, "rotate",
25 function (degrees, axis) {
26 var costheta = Math.cos ((degrees * 3.141592653589793) / 180.0);
27 var sintheta = Math.sin ((degrees * 3.141592653589793) / 180.0);
29 this.rot[0][0] = costheta;
30 this.rot[0][1] = -sintheta;
32 this.rot[1][0] = sintheta;
33 this.rot[1][1] = costheta;
38 this.preMultiply (this.rot);
44 this.rot[1][1] = costheta;
45 this.rot[1][2] = sintheta;
47 this.rot[2][1] = -sintheta;
48 this.rot[2][2] = costheta;
49 this.preMultiply (this.rot);
51 this.rot[0][0] = costheta;
53 this.rot[0][2] = -sintheta;
57 this.rot[2][0] = sintheta;
59 this.rot[2][2] = costheta;
60 this.preMultiply (this.rot);
62 Clazz.defineMethod (c$, "vectorMultiply",
64 this.temp[0] = vect[0];
65 this.temp[1] = vect[1];
66 this.temp[2] = vect[2];
67 for (var i = 0; i < 3; i++) {
68 this.temp[i] = (this.matrix[i][0] * vect[0]) + (this.matrix[i][1] * vect[1]) + (this.matrix[i][2] * vect[2]);
70 vect[0] = this.temp[0];
71 vect[1] = this.temp[1];
72 vect[2] = this.temp[2];
75 Clazz.defineMethod (c$, "preMultiply",
77 var tmp = Clazz.newFloatArray (3, 3, 0);
78 for (var i = 0; i < 3; i++) {
79 for (var j = 0; j < 3; j++) {
80 tmp[i][j] = (mat[i][0] * this.matrix[0][j]) + (mat[i][1] * this.matrix[1][j]) + (mat[i][2] * this.matrix[2][j]);
83 for (var i = 0; i < 3; i++) {
84 for (var j = 0; j < 3; j++) {
85 this.matrix[i][j] = tmp[i][j];
89 Clazz.defineMethod (c$, "postMultiply",
91 var tmp = Clazz.newFloatArray (3, 3, 0);
92 for (var i = 0; i < 3; i++) {
93 for (var j = 0; j < 3; j++) {
94 tmp[i][j] = (this.matrix[i][0] * mat[0][j]) + (this.matrix[i][1] * mat[1][j]) + (this.matrix[i][2] * mat[2][j]);
97 for (var i = 0; i < 3; i++) {
98 for (var j = 0; j < 3; j++) {
99 this.matrix[i][j] = tmp[i][j];
103 Clazz.defineMethod (c$, "setIdentity",
105 this.matrix[0][0] = 1.0;
106 this.matrix[1][1] = 1.0;
107 this.matrix[2][2] = 1.0;
108 this.matrix[0][1] = 0.0;
109 this.matrix[0][2] = 0.0;
110 this.matrix[1][0] = 0.0;
111 this.matrix[1][2] = 0.0;
112 this.matrix[2][0] = 0.0;
113 this.matrix[2][1] = 0.0;