2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
27 float myconst = (float) (Math.PI / 180);
29 public MCMatrix(int rows, int cols)
31 matrix = new float[rows][cols];
32 tmp = new float[rows][cols];
35 public void addElement(int i, int j, float value)
40 public void rotatex(float degrees)
42 mycos = (float) (Math.cos(degrees * myconst));
43 mysin = (float) (Math.sin(degrees * myconst));
57 public void rotatez(float degrees)
59 mycos = (float) (Math.cos(degrees * myconst));
60 mysin = (float) (Math.sin(degrees * myconst));
75 public void rotatey(float degrees)
77 mycos = (float) (Math.cos(degrees * myconst));
78 mysin = (float) (Math.sin(degrees * myconst));
93 public float[] vectorMultiply(float[] vect)
95 float[] temp = new float[3];
101 for (int i = 0; i < 3; i++)
103 temp[i] = ( (float) matrix[i][0] * vect[0]) +
104 ( (float) matrix[i][1] * vect[1]) +
105 ( (float) matrix[i][2] * vect[2]);
115 public void preMultiply(float[][] mat)
117 float[][] tmp = new float[3][3];
119 for (int i = 0; i < 3; i++)
121 for (int j = 0; j < 3; j++)
123 tmp[i][j] = (mat[i][0] * matrix[0][j]) +
124 (mat[i][1] * matrix[1][j]) + (mat[i][2] * matrix[2][j]);
128 for (int i = 0; i < 3; i++)
130 for (int j = 0; j < 3; j++)
132 matrix[i][j] = tmp[i][j];
137 public void postMultiply(float[][] mat)
139 float[][] tmp = new float[3][3];
141 for (int i = 0; i < 3; i++)
143 for (int j = 0; j < 3; j++)
145 tmp[i][j] = (matrix[i][0] * mat[0][j]) +
146 (matrix[i][1] * mat[1][j]) + (matrix[i][2] * mat[2][j]);
150 for (int i = 0; i < 3; i++)
152 for (int j = 0; j < 3; j++)
154 matrix[i][j] = tmp[i][j];
159 public void setIdentity()