2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
30 float myconst = (float) (Math.PI / 180);
32 public MCMatrix(int rows, int cols)
34 matrix = new float[rows][cols];
35 tmp = new float[rows][cols];
38 public void addElement(int i, int j, float value)
43 public void rotatex(float degrees)
45 mycos = (float) (Math.cos(degrees * myconst));
46 mysin = (float) (Math.sin(degrees * myconst));
60 public void rotatez(float degrees)
62 mycos = (float) (Math.cos(degrees * myconst));
63 mysin = (float) (Math.sin(degrees * myconst));
78 public void rotatey(float degrees)
80 mycos = (float) (Math.cos(degrees * myconst));
81 mysin = (float) (Math.sin(degrees * myconst));
96 public float[] vectorMultiply(float[] vect)
98 float[] temp = new float[3];
104 for (int i = 0; i < 3; i++)
106 temp[i] = ((float) matrix[i][0] * vect[0])
107 + ((float) matrix[i][1] * vect[1])
108 + ((float) matrix[i][2] * vect[2]);
118 public void preMultiply(float[][] mat)
120 float[][] tmp = new float[3][3];
122 for (int i = 0; i < 3; i++)
124 for (int j = 0; j < 3; j++)
126 tmp[i][j] = (mat[i][0] * matrix[0][j]) + (mat[i][1] * matrix[1][j])
127 + (mat[i][2] * matrix[2][j]);
131 for (int i = 0; i < 3; i++)
133 for (int j = 0; j < 3; j++)
135 matrix[i][j] = tmp[i][j];
140 public void postMultiply(float[][] mat)
142 float[][] tmp = new float[3][3];
144 for (int i = 0; i < 3; i++)
146 for (int j = 0; j < 3; j++)
148 tmp[i][j] = (matrix[i][0] * mat[0][j]) + (matrix[i][1] * mat[1][j])
149 + (matrix[i][2] * mat[2][j]);
153 for (int i = 0; i < 3; i++)
155 for (int j = 0; j < 3; j++)
157 matrix[i][j] = tmp[i][j];
162 public void setIdentity()