/* Auteur: Nicolas JANEY */ /* nicolas.janey@univ-fcomte.fr */ /* Novembre 2006 */ /* Transformation geometrique en coordonnees homogenes */ /* pour la realisation de rotations autour d'un axe */ /* arbitraire passant ou non par l'origine */ public class Rotation extends Transformation { public Rotation(float a, float dx,float dy,float dz) throws ArithmeticException { super(); remplissage(a,dx,dy,dz); } public Rotation(float a, Direction d) throws ArithmeticException { super(); remplissage(a,d.getX(),d.getY(),d.getZ()); } public Rotation(float a, float x,float y,float z, float dx,float dy,float dz) throws ArithmeticException { super(); remplissage(a,x,y,z,dx,dy,dz); } public Rotation(float a, Position p,Direction d) throws ArithmeticException { super(); remplissage(a,p.getX(),p.getY(),p.getZ(),d.getX(),d.getY(),d.getZ()); } private void remplissage(float a, float x,float y,float z) throws ArithmeticException { a = a/180.0F*(float) Math.PI; float c =(float) Math.cos(a); float s =(float) Math.sin(a); float d =(float) Math.sqrt(x*x+y*y+z*z); if ( d == 0 ) { throw new ArithmeticException(); } x /= d; y /= d; z /= d; float x2 = x*x; float y2 = y*y; float z2 = z*z; float xs = x*s; float ys = y*s; float zs = z*s; float mc = 1.0F - c; float xymc = x*y*mc; float xzmc = x*z*mc; float yzmc = y*z*mc; this.c[0][0] = x2+c*(1.0F-x2); this.c[0][1] = xymc-zs; this.c[0][2] = xzmc+ys; this.c[1][0] = xymc+zs; this.c[1][1] = y2+c*(1.0F-y2); this.c[1][2] = yzmc-xs; this.c[2][0] = xzmc-ys; this.c[2][1] = yzmc+xs; this.c[2][2] = z2+c*(1.0F-z2); } private void remplissage(float a, float px,float py,float pz, float ax,float ay,float az) throws ArithmeticException { Translation ti = new Translation(-px,-py,-pz); Rotation r = new Rotation(a,ax,ay,az); Translation tf = new Translation(px,py,pz); Transformation t = tf.multiplication(r).multiplication(ti); for ( int i = 0 ; i < 4 ; i++ ) for ( int j = 0 ; j < 4 ; j++ ) c[i][j] = t.c[i][j]; } }