/* Auteur: Nicolas JANEY */ /* nicolas.janey@univ-fcomte.fr */ /* Octobre 2008 */ /* Une classe transformation geometrique 3D */ /* en coordonnees homogenes */ public class TransformationGeometrique3D { protected double [][] c; public TransformationGeometrique3D() { c = new double[4][4]; for ( int i = 0 ; i < 4 ; i++ ) c[i][i] = 1.0; } public TransformationGeometrique3D(double [][] t) { c = new double[4][4]; for ( int i = 0 ; i < 4 ; i++ ) for ( int j = 0 ; j < 4 ; j++ ) c[i][j] = t[i][j]; } public TransformationGeometrique3D(TransformationGeometrique3D t) { c = new double[4][4]; for ( int i = 0 ; i < 4 ; i++ ) for ( int j = 0 ; j < 4 ; j++ ) c[i][j] = t.c[i][j]; } public Position3D transform(Position3D p) { double [] v = multiplication(p.getValue()); return(new Position3D(v[0],v[1],v[2])); } public Direction3D transform(Direction3D d) { double [] v = multiplication(d.getValue()); return(new Direction3D(v[0],v[1],v[2])); } private double [] multiplication(double [] v) { double [] r = new double[4]; for ( int i = 0 ; i < 4 ; i++ ) for ( int j = 0 ; j < 4 ; j++ ) r[i] += c[i][j]*v[j]; return(r); } public TransformationGeometrique3D compose(TransformationGeometrique3D m) { TransformationGeometrique3D r = new TransformationGeometrique3D(); for ( int i = 0 ; i < 4 ; i++ ) for ( int j = 0 ; j < 4 ; j++ ) { r.c[i][j] = 0.0; for ( int k = 0 ; k < 4 ; k++ ) r.c[i][j] += c[i][k]*m.c[k][j]; } return(r); } public static TransformationGeometrique3D compose(TransformationGeometrique3D m1, TransformationGeometrique3D m2) { return(m1.compose(m2)); } public String toString() { String s = "["; for ( int j = 0 ; j < c.length ; j++ ) { if ( j > 0 ) s += " "; s += "["; for ( int i = 0 ; i < c[j].length ; i++ ) { s += c[j][i]; if ( i < c[j].length-1 ) s += ","; } s += "]"; if ( j < c.length-1 ) s += "\n"; } s += "]"; return(s); } }