X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2FMCview%2FMCMatrix.java;h=1dbec226fa26060fdfb7348bc23bb9171f6a549d;hb=87e3f6da091c04a6a9277f5294f586f454bcf0e1;hp=31af9d4fac8b0bacd5cd00c95463c53178a05e3d;hpb=99c58ee0ae2a848f982552e53feaf6d5cb9925e5;p=jalview.git diff --git a/src/MCview/MCMatrix.java b/src/MCview/MCMatrix.java index 31af9d4..1dbec22 100755 --- a/src/MCview/MCMatrix.java +++ b/src/MCview/MCMatrix.java @@ -1,6 +1,6 @@ /* * Jalview - A Sequence Alignment Editor and Viewer -* Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle +* Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -16,147 +16,137 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ - package MCview; public class MCMatrix { - float matrix[][]; - float tmp[][]; - - float mycos; - float mysin; - float myconst = (float)(Math.PI/180); - - public MCMatrix(int rows, int cols) { - matrix = new float[rows][cols]; - tmp = new float[rows][cols]; - } - - public void addElement(int i, int j, float value) { - matrix[i][j] = value; - } - - public void print() { - System.out.println(matrix[0][0] + " " + matrix[0][1] + " " + matrix[0][2]); - System.out.println(matrix[1][0] + " " + matrix[1][1] + " " + matrix[1][2]); - System.out.println(matrix[2][0] + " " + matrix[2][1] + " " + matrix[2][2]); - } - - public void rotatex(float degrees) { - mycos = (float)(Math.cos(degrees*myconst)); - mysin = (float)(Math.sin(degrees*myconst)); - - tmp[0][0] = 1; - tmp[0][1] = 0; - tmp[0][2] = 0; - tmp[1][0] = 0; - tmp[1][1] = mycos; - tmp[1][2] = mysin; - tmp[2][0] = 0; - tmp[2][1] = -mysin; - tmp[2][2] = mycos; - preMultiply(tmp); - } - - public void rotatez(float degrees) { - mycos = (float)(Math.cos(degrees*myconst)); - mysin = (float)(Math.sin(degrees*myconst)); - - tmp[0][0] = mycos; - tmp[0][1] = -mysin; - tmp[0][2] = 0; - tmp[1][0] = mysin; - tmp[1][1] = mycos; - tmp[1][2] = 0; - tmp[2][0] = 0; - tmp[2][1] = 0; - tmp[2][2] = 1; - - preMultiply(tmp); - } - - public void rotatey(float degrees) { - mycos = (float)(Math.cos(degrees*myconst)); - mysin = (float)(Math.sin(degrees*myconst)); - - tmp[0][0] = mycos; - tmp[0][1] = 0; - tmp[0][2] = -mysin; - tmp[1][0] = 0; - tmp[1][1] = 1; - tmp[1][2] = 0; - tmp[2][0] = mysin; - tmp[2][1] = 0; - tmp[2][2] = mycos; - - preMultiply(tmp); - } - - public float[] vectorMultiply(float[] vect) { - float temp[] = new float[3]; - - temp[0] = vect[0]; - temp[1] = vect[1]; - temp[2] = vect[2]; - - for (int i = 0; i < 3; i++) { - temp[i] = (float)matrix[i][0]*vect[0] + (float)matrix[i][1]*vect[1] +(float)matrix[i][2]*vect[2]; + float[][] matrix; + float[][] tmp; + float mycos; + float mysin; + float myconst = (float) (Math.PI / 180); + + public MCMatrix(int rows, int cols) { + matrix = new float[rows][cols]; + tmp = new float[rows][cols]; } - vect[0] = temp[0]; - vect[1] = temp[1]; - vect[2] = temp[2]; - - return vect; - } + public void addElement(int i, int j, float value) { + matrix[i][j] = value; + } - public void preMultiply(float mat[][]) { - float tmp[][] = new float[3][3]; + public void rotatex(float degrees) { + mycos = (float) (Math.cos(degrees * myconst)); + mysin = (float) (Math.sin(degrees * myconst)); + + tmp[0][0] = 1; + tmp[0][1] = 0; + tmp[0][2] = 0; + tmp[1][0] = 0; + tmp[1][1] = mycos; + tmp[1][2] = mysin; + tmp[2][0] = 0; + tmp[2][1] = -mysin; + tmp[2][2] = mycos; + preMultiply(tmp); + } - for (int i = 0; i < 3 ; i++) { - for (int j = 0; j < 3; j++ ) { - tmp[i][j] = mat[i][0]*matrix[0][j] + - mat[i][1]*matrix[1][j] + - mat[i][2]*matrix[2][j]; - } + public void rotatez(float degrees) { + mycos = (float) (Math.cos(degrees * myconst)); + mysin = (float) (Math.sin(degrees * myconst)); + + tmp[0][0] = mycos; + tmp[0][1] = -mysin; + tmp[0][2] = 0; + tmp[1][0] = mysin; + tmp[1][1] = mycos; + tmp[1][2] = 0; + tmp[2][0] = 0; + tmp[2][1] = 0; + tmp[2][2] = 1; + + preMultiply(tmp); } - for (int i = 0; i < 3 ; i++) { - for (int j = 0; j < 3; j++ ) { - matrix[i][j] = tmp[i][j]; - } + public void rotatey(float degrees) { + mycos = (float) (Math.cos(degrees * myconst)); + mysin = (float) (Math.sin(degrees * myconst)); + + tmp[0][0] = mycos; + tmp[0][1] = 0; + tmp[0][2] = -mysin; + tmp[1][0] = 0; + tmp[1][1] = 1; + tmp[1][2] = 0; + tmp[2][0] = mysin; + tmp[2][1] = 0; + tmp[2][2] = mycos; + + preMultiply(tmp); } - } - public void postMultiply(float mat[][]) { - float tmp[][] = new float[3][3]; + public float[] vectorMultiply(float[] vect) { + float[] temp = new float[3]; + + temp[0] = vect[0]; + temp[1] = vect[1]; + temp[2] = vect[2]; + + for (int i = 0; i < 3; i++) { + temp[i] = ((float) matrix[i][0] * vect[0]) + + ((float) matrix[i][1] * vect[1]) + + ((float) matrix[i][2] * vect[2]); + } - for (int i = 0; i < 3 ; i++) { - for (int j = 0; j < 3; j++ ) { - tmp[i][j] = matrix[i][0]*mat[0][j] + - matrix[i][1]*mat[1][j] + - matrix[i][2]*mat[2][j]; - } + vect[0] = temp[0]; + vect[1] = temp[1]; + vect[2] = temp[2]; + + return vect; } - for (int i = 0; i < 3 ; i++) { - for (int j = 0; j < 3; j++ ) { - matrix[i][j] = tmp[i][j]; - } + public void preMultiply(float[][] mat) { + float[][] tmp = new float[3][3]; + + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + tmp[i][j] = (mat[i][0] * matrix[0][j]) + + (mat[i][1] * matrix[1][j]) + (mat[i][2] * matrix[2][j]); + } + } + + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + matrix[i][j] = tmp[i][j]; + } + } } - } - - public void setIdentity() { - matrix[0][0] = 1; - matrix[1][1] = 1; - matrix[2][2] = 1; - matrix[0][1] = 0; - matrix[0][2] = 0; - matrix[1][0] = 0; - matrix[1][2] = 0; - matrix[2][0] = 0; - matrix[2][1] = 0; - } -} + public void postMultiply(float[][] mat) { + float[][] tmp = new float[3][3]; + + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + tmp[i][j] = (matrix[i][0] * mat[0][j]) + + (matrix[i][1] * mat[1][j]) + (matrix[i][2] * mat[2][j]); + } + } + + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + matrix[i][j] = tmp[i][j]; + } + } + } + public void setIdentity() { + matrix[0][0] = 1; + matrix[1][1] = 1; + matrix[2][2] = 1; + matrix[0][1] = 0; + matrix[0][2] = 0; + matrix[1][0] = 0; + matrix[1][2] = 0; + matrix[2][0] = 0; + matrix[2][1] = 0; + } +}