1    /*
2    Copyright 2000 by Ralph Hartley
3    This software is licenced under the terms of the
4    Gnu Public Licence
5    */
6    public class Matrix {
7            public double[][] element;
8    
9            public Matrix() {
10           	element = new double[3][4];
11           	element[0][0] = 1.0;
12           	element[1][1] = 1.0;
13           	element[2][2] = 1.0;
14           }
15           public Matrix(double scale) {
16           	element = new double[3][4];
17           	element[0][0] = scale;
18           	element[1][1] = scale;
19           	element[2][2] = scale;
20           }
21   public Matrix(Matrix A) {
22           	int i;
23           	int j;
24           	element = new double[3][4];
25   
26           	for (i=0;i<3;i++)
27           		for (j=0;j<4;j++)
28           				element[i][j] += A.element[i][j];
29           }
30           public Matrix(Matrix A,Matrix B) {
31           	int i;
32           	int j;
33           	int k;
34           	element = new double[3][4];
35   
36           	for (i=0;i<3;i++) {
37           		element[i][3] = A.element[i][3];
38           		for (j=0;j<4;j++)
39           			for (k=0;k<3;k++)
40           				element[i][j] += A.element[i][k] * B.element[k][j];
41           		}
42           }
43           public Matrix(Vect shift) {
44           	element = new double[3][4];
45           	element[0][0] = 1.0;
46           	element[1][1] = 1.0;
47           	element[2][2] = 1.0;
48           	for (int i=0;i<3;i++)
49           	  element[i][3] = shift.X[i];
50           }
51           public Matrix(Vect ax, double angle){
52           	double[] axis = ax.X;
53           	element = new double[3][4];
54           	double s = Math.sin(angle);
55           	double c = Math.cos(angle);
56           	double t = 1.0-c;
57           	element[0][0] = t*axis[0]*axis[0]+c;
58           	element[0][1] = t*axis[0]*axis[1]+s*axis[2];
59           	element[0][2] = t*axis[0]*axis[2]-s*axis[1];
60           	element[1][0] = t*axis[1]*axis[0]-s*axis[2];
61           	element[1][1] = t*axis[1]*axis[1]+c;
62           	element[1][2] = t*axis[1]*axis[2]+s*axis[0];
63           	element[2][0] = t*axis[2]*axis[0]+s*axis[1];
64           	element[2][1] = t*axis[2]*axis[1]-s*axis[0];
65           	element[2][2] = t*axis[2]*axis[2]+c;
66           }
67           public void print() {
68           	int i;
69           	for (i=0;i<3;i++)
70           			System.out.println(element[i][0]+" "+element[i][1]+" "+element[i][2]);
71             System.out.println(" ");
72     }    
73           public void scale(double fact) {
74           	int i;
75           	int j;
76           	for (i=0;i<3;i++)
77           		for (j=0;j<4;j++)
78           			element[i][j] *= fact;
79           }
80           public double[] XY(Vect V) {
81           int j;
82           	double[] res = new double[2];
83           	for (int i=0;i<2;i++) {
84           		res[i] = element[i][3];
85           		for (j=0;j<3;j++)
86           			res[i] += V.X[j]*element[i][j];
87           }
88           	return(res);
89           }
90           public double Z(Vect V) {
91           	double res = element[2][3];
92           	for (int j=0;j<3;j++)
93           		res += V.X[j]*element[2][j];
94           	return(res);
95           }
96   }
97