Class |
Line # |
Actions |
|||
---|---|---|---|---|---|
MCMatrix | 23 | 72 | 18 |
1 | /* | |
2 | * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) | |
3 | * Copyright (C) $$Year-Rel$$ The Jalview Authors | |
4 | * | |
5 | * This file is part of Jalview. | |
6 | * | |
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 | |
10 | * of the License, or (at your option) any later version. | |
11 | * | |
12 | * Jalview is distributed in the hope that it will be useful, but | |
13 | * WITHOUT ANY WARRANTY; without even the implied warranty | |
14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR | |
15 | * PURPOSE. See the GNU General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
18 | * along with Jalview. If not, see <http://www.gnu.org/licenses/>. | |
19 | * The Jalview Authors are detailed in the 'AUTHORS' file. | |
20 | */ | |
21 | package mc_view; | |
22 | ||
23 | public class MCMatrix | |
24 | { | |
25 | float[][] matrix; | |
26 | ||
27 | float[][] tmp; | |
28 | ||
29 | float mycos; | |
30 | ||
31 | float mysin; | |
32 | ||
33 | float myconst = (float) (Math.PI / 180); | |
34 | ||
35 | 0 | public MCMatrix(int rows, int cols) |
36 | { | |
37 | 0 | matrix = new float[rows][cols]; |
38 | 0 | tmp = new float[rows][cols]; |
39 | } | |
40 | ||
41 | 0 | public void addElement(int i, int j, float value) |
42 | { | |
43 | 0 | matrix[i][j] = value; |
44 | } | |
45 | ||
46 | 0 | public void rotatex(float degrees) |
47 | { | |
48 | 0 | mycos = (float) (Math.cos(degrees * myconst)); |
49 | 0 | mysin = (float) (Math.sin(degrees * myconst)); |
50 | ||
51 | 0 | tmp[0][0] = 1; |
52 | 0 | tmp[0][1] = 0; |
53 | 0 | tmp[0][2] = 0; |
54 | 0 | tmp[1][0] = 0; |
55 | 0 | tmp[1][1] = mycos; |
56 | 0 | tmp[1][2] = mysin; |
57 | 0 | tmp[2][0] = 0; |
58 | 0 | tmp[2][1] = -mysin; |
59 | 0 | tmp[2][2] = mycos; |
60 | 0 | preMultiply(tmp); |
61 | } | |
62 | ||
63 | 0 | public void rotatez(float degrees) |
64 | { | |
65 | 0 | mycos = (float) (Math.cos(degrees * myconst)); |
66 | 0 | mysin = (float) (Math.sin(degrees * myconst)); |
67 | ||
68 | 0 | tmp[0][0] = mycos; |
69 | 0 | tmp[0][1] = -mysin; |
70 | 0 | tmp[0][2] = 0; |
71 | 0 | tmp[1][0] = mysin; |
72 | 0 | tmp[1][1] = mycos; |
73 | 0 | tmp[1][2] = 0; |
74 | 0 | tmp[2][0] = 0; |
75 | 0 | tmp[2][1] = 0; |
76 | 0 | tmp[2][2] = 1; |
77 | ||
78 | 0 | preMultiply(tmp); |
79 | } | |
80 | ||
81 | 0 | public void rotatey(float degrees) |
82 | { | |
83 | 0 | mycos = (float) (Math.cos(degrees * myconst)); |
84 | 0 | mysin = (float) (Math.sin(degrees * myconst)); |
85 | ||
86 | 0 | tmp[0][0] = mycos; |
87 | 0 | tmp[0][1] = 0; |
88 | 0 | tmp[0][2] = -mysin; |
89 | 0 | tmp[1][0] = 0; |
90 | 0 | tmp[1][1] = 1; |
91 | 0 | tmp[1][2] = 0; |
92 | 0 | tmp[2][0] = mysin; |
93 | 0 | tmp[2][1] = 0; |
94 | 0 | tmp[2][2] = mycos; |
95 | ||
96 | 0 | preMultiply(tmp); |
97 | } | |
98 | ||
99 | 0 | public float[] vectorMultiply(float[] vect) |
100 | { | |
101 | 0 | float[] temp = new float[3]; |
102 | ||
103 | 0 | temp[0] = vect[0]; |
104 | 0 | temp[1] = vect[1]; |
105 | 0 | temp[2] = vect[2]; |
106 | ||
107 | 0 | for (int i = 0; i < 3; i++) |
108 | { | |
109 | 0 | temp[i] = ((float) matrix[i][0] * vect[0]) |
110 | + ((float) matrix[i][1] * vect[1]) | |
111 | + ((float) matrix[i][2] * vect[2]); | |
112 | } | |
113 | ||
114 | 0 | vect[0] = temp[0]; |
115 | 0 | vect[1] = temp[1]; |
116 | 0 | vect[2] = temp[2]; |
117 | ||
118 | 0 | return vect; |
119 | } | |
120 | ||
121 | 0 | public void preMultiply(float[][] mat) |
122 | { | |
123 | 0 | float[][] tmp = new float[3][3]; |
124 | ||
125 | 0 | for (int i = 0; i < 3; i++) |
126 | { | |
127 | 0 | for (int j = 0; j < 3; j++) |
128 | { | |
129 | 0 | tmp[i][j] = (mat[i][0] * matrix[0][j]) + (mat[i][1] * matrix[1][j]) |
130 | + (mat[i][2] * matrix[2][j]); | |
131 | } | |
132 | } | |
133 | ||
134 | 0 | for (int i = 0; i < 3; i++) |
135 | { | |
136 | 0 | for (int j = 0; j < 3; j++) |
137 | { | |
138 | 0 | matrix[i][j] = tmp[i][j]; |
139 | } | |
140 | } | |
141 | } | |
142 | ||
143 | 0 | public void postMultiply(float[][] mat) |
144 | { | |
145 | 0 | float[][] tmp = new float[3][3]; |
146 | ||
147 | 0 | for (int i = 0; i < 3; i++) |
148 | { | |
149 | 0 | for (int j = 0; j < 3; j++) |
150 | { | |
151 | 0 | tmp[i][j] = (matrix[i][0] * mat[0][j]) + (matrix[i][1] * mat[1][j]) |
152 | + (matrix[i][2] * mat[2][j]); | |
153 | } | |
154 | } | |
155 | ||
156 | 0 | for (int i = 0; i < 3; i++) |
157 | { | |
158 | 0 | for (int j = 0; j < 3; j++) |
159 | { | |
160 | 0 | matrix[i][j] = tmp[i][j]; |
161 | } | |
162 | } | |
163 | } | |
164 | ||
165 | 0 | public void setIdentity() |
166 | { | |
167 | 0 | matrix[0][0] = 1; |
168 | 0 | matrix[1][1] = 1; |
169 | 0 | matrix[2][2] = 1; |
170 | 0 | matrix[0][1] = 0; |
171 | 0 | matrix[0][2] = 0; |
172 | 0 | matrix[1][0] = 0; |
173 | 0 | matrix[1][2] = 0; |
174 | 0 | matrix[2][0] = 0; |
175 | 0 | matrix[2][1] = 0; |
176 | } | |
177 | } |