Advertisement
thibthibaut

Shampoing0001

Nov 4th, 2015
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.69 KB | None | 0 0
  1.  
  2.     /** MATRIX ROTATION 1
  3.      * Première methode de rotation de matrice
  4.      * Problème: La matrice d'arrivée contient des trous
  5.      * liés à l'arondi du calcul des coordonées
  6.      *
  7.      * Nouvelle version : Utilisation d'une symétrie centrale pour réduire le temps de calcul
  8.      *
  9.      * Temps d'exectution dans le simulateur : 28000 ,111994 ms
  10.      *
  11.      * author: Thibaut Vercueil, groupe 10
  12.      * @param inputMatrix La matrice d'entrée
  13.      * @param angle L'angle à rentrer en RADIAN
  14.      */
  15.     void rotateMatrix1(BImage inputMatrix, double angle) {
  16.        
  17.         int length = inputMatrix.ARGB.length;
  18.        
  19.         angle %= 2*3.14;
  20.        
  21.         //Calcul des cosinus et sinus
  22.         double cos = Math.cos( angle, 15);
  23.         double sin = Math.sin( angle, 15);
  24.         double minus_sin = -sin;
  25.        
  26.         //Création de la nouvelle de matrices aux dimensions idéales
  27.         double cos_plus_sin = Math.abs(cos) + Math.abs(sin);
  28.         outputMatrix = new Matrix((int)( cos_plus_sin*inputMatrix.width) , (int)( cos_plus_sin*inputMatrix.width  ));
  29.         //for(int k = 0; k<outputMatrix.mat.length; k++) outputMatrix.mat[k] = 0xFFFFFF;//FILL WIHT WHITE
  30.         int width = inputMatrix.width;
  31.         int newWidth = outputMatrix.width;
  32.        
  33.         int offset_x = 0;
  34.         int offset_y = 0;
  35.        
  36.         //Calcul des points extremes    
  37.         int top_r_x = (int) (  (width-1) * cos );
  38.         int top_r_y = (int) ( -(width-1) * sin );
  39.        
  40.         int bot_r_x = (int) (  (width-1) * cos + (width-1) * sin );
  41.         int bot_r_y = (int) ( -(width-1) * sin + (width-1) * cos );
  42.        
  43.         int bot_l_x = (int) ( width-1 * sin );
  44.         int bot_l_y = (int) ( width-1 * cos );
  45.        
  46.         //Calculs des offsets sur x et y
  47.         if(angle >= 0 && angle < 3.14/2){
  48.             offset_y = -top_r_y;
  49.         }
  50.        
  51.         if(angle >= 3.14/2 && angle < 3.14){
  52.             offset_y = -bot_r_y;
  53.             offset_x = -top_r_x;
  54.         }
  55.        
  56.         if(angle >= 3.14 && angle < (3*3.14)/2 ){
  57.             offset_y = -bot_l_y;
  58.             offset_x = -bot_r_x;
  59.         }
  60.        
  61.         if(angle >= (3*3.14)/2 && angle < 2*3.14 ){
  62.             offset_x = -bot_l_x;
  63.         }
  64.        
  65.         int i, i_out, x_in, y_in, x_out, y_out;
  66.         double sinyin =0, cosyin = 0;
  67.        
  68.         int half_lenght = length>>1; //Divide by 2
  69.         int newLength = outputMatrix.mat.length;
  70.        
  71.         y_in = -1;
  72.         //Boucle principale
  73.         for(i=0; i<half_lenght; i++){
  74.            
  75.             x_in = i % width;
  76.             if(x_in  == 0){
  77.                 y_in++;
  78.                 sinyin = y_in*sin;
  79.                 cosyin = y_in * cos;
  80.             }
  81.             //y_in = i / width;
  82.            
  83.             x_out =   (int)(x_in * cos+ sinyin) + offset_x ;
  84.             y_out = (int)(x_in * minus_sin + cosyin) + offset_y ;
  85.            
  86.                
  87.             i_out = x_out + newWidth*y_out;
  88.            
  89.             outputMatrix.mat[i_out]=inputMatrix.ARGB[i];
  90.             outputMatrix.mat[newLength - i_out - 1 ]=inputMatrix.ARGB[length-i-1]; //On utilise la symétrie pour remplir a partir de la fin de l'image
  91.            
  92.             if(i%100==0) repaint();
  93.         }
  94.            
  95.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement