2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
22 public class MCMatrix {
\r
28 float myconst = (float)(Math.PI/180);
\r
30 public MCMatrix(int rows, int cols) {
\r
31 matrix = new float[rows][cols];
\r
32 tmp = new float[rows][cols];
\r
35 public void addElement(int i, int j, float value) {
\r
36 matrix[i][j] = value;
\r
39 public void print() {
\r
40 System.out.println(matrix[0][0] + " " + matrix[0][1] + " " + matrix[0][2]);
\r
41 System.out.println(matrix[1][0] + " " + matrix[1][1] + " " + matrix[1][2]);
\r
42 System.out.println(matrix[2][0] + " " + matrix[2][1] + " " + matrix[2][2]);
\r
45 public void rotatex(float degrees) {
\r
46 mycos = (float)(Math.cos(degrees*myconst));
\r
47 mysin = (float)(Math.sin(degrees*myconst));
\r
61 public void rotatez(float degrees) {
\r
62 mycos = (float)(Math.cos(degrees*myconst));
\r
63 mysin = (float)(Math.sin(degrees*myconst));
\r
78 public void rotatey(float degrees) {
\r
79 mycos = (float)(Math.cos(degrees*myconst));
\r
80 mysin = (float)(Math.sin(degrees*myconst));
\r
95 public float[] vectorMultiply(float[] vect) {
\r
96 float temp[] = new float[3];
\r
102 for (int i = 0; i < 3; i++) {
\r
103 temp[i] = (float)matrix[i][0]*vect[0] + (float)matrix[i][1]*vect[1] +(float)matrix[i][2]*vect[2];
\r
113 public void preMultiply(float mat[][]) {
\r
114 float tmp[][] = new float[3][3];
\r
116 for (int i = 0; i < 3 ; i++) {
\r
117 for (int j = 0; j < 3; j++ ) {
\r
118 tmp[i][j] = mat[i][0]*matrix[0][j] +
\r
119 mat[i][1]*matrix[1][j] +
\r
120 mat[i][2]*matrix[2][j];
\r
124 for (int i = 0; i < 3 ; i++) {
\r
125 for (int j = 0; j < 3; j++ ) {
\r
126 matrix[i][j] = tmp[i][j];
\r
131 public void postMultiply(float mat[][]) {
\r
132 float tmp[][] = new float[3][3];
\r
134 for (int i = 0; i < 3 ; i++) {
\r
135 for (int j = 0; j < 3; j++ ) {
\r
136 tmp[i][j] = matrix[i][0]*mat[0][j] +
\r
137 matrix[i][1]*mat[1][j] +
\r
138 matrix[i][2]*mat[2][j];
\r
142 for (int i = 0; i < 3 ; i++) {
\r
143 for (int j = 0; j < 3; j++ ) {
\r
144 matrix[i][j] = tmp[i][j];
\r
149 public void setIdentity() {
\r