2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
3 * Copyright (C) 2014 The Jalview Authors
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/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
31 float myconst = (float) (Math.PI / 180);
33 public MCMatrix(int rows, int cols)
35 matrix = new float[rows][cols];
36 tmp = new float[rows][cols];
39 public void addElement(int i, int j, float value)
44 public void rotatex(float degrees)
46 mycos = (float) (Math.cos(degrees * myconst));
47 mysin = (float) (Math.sin(degrees * myconst));
61 public void rotatez(float degrees)
63 mycos = (float) (Math.cos(degrees * myconst));
64 mysin = (float) (Math.sin(degrees * myconst));
79 public void rotatey(float degrees)
81 mycos = (float) (Math.cos(degrees * myconst));
82 mysin = (float) (Math.sin(degrees * myconst));
97 public float[] vectorMultiply(float[] vect)
99 float[] temp = new float[3];
105 for (int i = 0; i < 3; i++)
107 temp[i] = ((float) matrix[i][0] * vect[0])
108 + ((float) matrix[i][1] * vect[1])
109 + ((float) matrix[i][2] * vect[2]);
119 public void preMultiply(float[][] mat)
121 float[][] tmp = new float[3][3];
123 for (int i = 0; i < 3; i++)
125 for (int j = 0; j < 3; j++)
127 tmp[i][j] = (mat[i][0] * matrix[0][j]) + (mat[i][1] * matrix[1][j])
128 + (mat[i][2] * matrix[2][j]);
132 for (int i = 0; i < 3; i++)
134 for (int j = 0; j < 3; j++)
136 matrix[i][j] = tmp[i][j];
141 public void postMultiply(float[][] mat)
143 float[][] tmp = new float[3][3];
145 for (int i = 0; i < 3; i++)
147 for (int j = 0; j < 3; j++)
149 tmp[i][j] = (matrix[i][0] * mat[0][j]) + (matrix[i][1] * mat[1][j])
150 + (matrix[i][2] * mat[2][j]);
154 for (int i = 0; i < 3; i++)
156 for (int j = 0; j < 3; j++)
158 matrix[i][j] = tmp[i][j];
163 public void setIdentity()