2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 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
21 public class MCMatrix {
26 float myconst = (float) (Math.PI / 180);
28 public MCMatrix(int rows, int cols) {
29 matrix = new float[rows][cols];
30 tmp = new float[rows][cols];
33 public void addElement(int i, int j, float value) {
37 public void rotatex(float degrees) {
38 mycos = (float) (Math.cos(degrees * myconst));
39 mysin = (float) (Math.sin(degrees * myconst));
53 public void rotatez(float degrees) {
54 mycos = (float) (Math.cos(degrees * myconst));
55 mysin = (float) (Math.sin(degrees * myconst));
70 public void rotatey(float degrees) {
71 mycos = (float) (Math.cos(degrees * myconst));
72 mysin = (float) (Math.sin(degrees * myconst));
87 public float[] vectorMultiply(float[] vect) {
88 float[] temp = new float[3];
94 for (int i = 0; i < 3; i++) {
95 temp[i] = ((float) matrix[i][0] * vect[0]) +
96 ((float) matrix[i][1] * vect[1]) +
97 ((float) matrix[i][2] * vect[2]);
107 public void preMultiply(float[][] mat) {
108 float[][] tmp = new float[3][3];
110 for (int i = 0; i < 3; i++) {
111 for (int j = 0; j < 3; j++) {
112 tmp[i][j] = (mat[i][0] * matrix[0][j]) +
113 (mat[i][1] * matrix[1][j]) + (mat[i][2] * matrix[2][j]);
117 for (int i = 0; i < 3; i++) {
118 for (int j = 0; j < 3; j++) {
119 matrix[i][j] = tmp[i][j];
124 public void postMultiply(float[][] mat) {
125 float[][] tmp = new float[3][3];
127 for (int i = 0; i < 3; i++) {
128 for (int j = 0; j < 3; j++) {
129 tmp[i][j] = (matrix[i][0] * mat[0][j]) +
130 (matrix[i][1] * mat[1][j]) + (matrix[i][2] * mat[2][j]);
134 for (int i = 0; i < 3; i++) {
135 for (int j = 0; j < 3; j++) {
136 matrix[i][j] = tmp[i][j];
141 public void setIdentity() {