/*----------------------------------------------------------------------*/ /* O4matrix - 4D orthogonal matrices (orientation matrices) - methods: Rotation - gives a rotation matrix in a coordinate plane Times - does matrix multiplication Equal - sets M = another O4matrix Tranpose - returns the tranpose (which is the inverse here) FindTran - given 2 matrices it finds the angle of rotation between them and also the plane of rotation Assign - 9 floats */ /*----------------------------------------------------------------------*/ /* Jim Morey -- morey@math.ubc.ca -- January 24, 1996 */ /*----------------------------------------------------------------------*/ public class O4matrix extends Object{ public double[][] M; private int row,col,k,l; O4matrix(){ M = new double[4][4]; Assign(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1); } /* - - - - - - - - - - - - - - - */ public void Assign(double a00, double a10, double a20, double a30, double a01, double a11, double a21, double a31, double a02, double a12, double a22, double a32, double a03, double a13, double a23, double a33 ){ M[0][0] = a00; M[1][0] = a10; M[2][0] = a20; M[3][0] = a30; M[0][1] = a01; M[1][1] = a11; M[2][1] = a21; M[3][1] = a31; M[0][2] = a02; M[1][2] = a12; M[2][2] = a22; M[3][2] = a32; M[0][3] = a03; M[1][3] = a13; M[2][3] = a23; M[3][3] = a33; } /* - - - - - - - - - - - - - - - */ public void Rotation (int i, int j, double angle) { Assign(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1); M[i][i] = Math.cos(angle); M[j][j] = M[i][i]; M[i][j] = Math.sin(angle); M[j][i] = -M[i][j]; } /* - - - - - - - - - - - - - - - */ public O4matrix Times(O4matrix N){ O4matrix temp = new O4matrix(); for (row=0; row < 4; row++) { for (col=0; col <4; col++) { temp.M[row][col] = 0.0; for (k=0; k < 4; k++) { temp.M[row][col] += M[row][k] * N.M[k][col]; } } } return temp; } /* - - - - - - - - - - - - - - - */ public void Equal(O4matrix N){ for (row=0; row < 4; row++) { for (col=0; col <4; col++) { M[row][col] = N.M[row][col]; } } } /* - - - - - - - - - - - - - - - */ public O4matrix Transpose(){ O4matrix temp = new O4matrix(); for (row=0; row < 4; row++) { for (col=0; col <4; col++) { temp.M[row][col]=M[col][row]; } } return temp; } /* - - - - - - - - - - - - - - - */ private void ExRow(int i, int j){ double swap; for (col=0; col <4; col++) { swap = M[i][col]; M[i][col] = M[j][col]; M[j][col] = swap; } } /* - - - - - - - - - - - - - - - */ private void RowAdd(int i, double s1, int j, double s2){ for (col=0; col <4; col++) M[i][col] = M[i][col]*s1 + M[j][col]*s2; } /* - - - - - - - - - - - - - - - */ public String toString() { String str; str = "O4matrix "; for (row=0;row<4;row++){ str = str.concat(row+">>("); for (col=0;col<4;col++) str = str.concat(" "+M[row][col]); str = str.concat(")\n "); } return str; } }