Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** MATRIX ROTATION 1
- * Première methode de rotation de matrice
- * Problème: La matrice d'arrivée contient des trous
- * liés à l'arondi du calcul des coordonées
- *
- * Nouvelle version : Utilisation d'une symétrie centrale pour réduire le temps de calcul
- *
- * Temps d'exectution dans le simulateur : 28000 ,111994 ms
- *
- * author: Thibaut Vercueil, groupe 10
- * @param inputMatrix La matrice d'entrée
- * @param angle L'angle à rentrer en RADIAN
- */
- void rotateMatrix1(BImage inputMatrix, double angle) {
- int length = inputMatrix.ARGB.length;
- angle %= 2*3.14;
- //Calcul des cosinus et sinus
- double cos = Math.cos( angle, 15);
- double sin = Math.sin( angle, 15);
- double minus_sin = -sin;
- //Création de la nouvelle de matrices aux dimensions idéales
- double cos_plus_sin = Math.abs(cos) + Math.abs(sin);
- outputMatrix = new Matrix((int)( cos_plus_sin*inputMatrix.width) , (int)( cos_plus_sin*inputMatrix.width ));
- //for(int k = 0; k<outputMatrix.mat.length; k++) outputMatrix.mat[k] = 0xFFFFFF;//FILL WIHT WHITE
- int width = inputMatrix.width;
- int newWidth = outputMatrix.width;
- int offset_x = 0;
- int offset_y = 0;
- //Calcul des points extremes
- int top_r_x = (int) ( (width-1) * cos );
- int top_r_y = (int) ( -(width-1) * sin );
- int bot_r_x = (int) ( (width-1) * cos + (width-1) * sin );
- int bot_r_y = (int) ( -(width-1) * sin + (width-1) * cos );
- int bot_l_x = (int) ( width-1 * sin );
- int bot_l_y = (int) ( width-1 * cos );
- //Calculs des offsets sur x et y
- if(angle >= 0 && angle < 3.14/2){
- offset_y = -top_r_y;
- }
- if(angle >= 3.14/2 && angle < 3.14){
- offset_y = -bot_r_y;
- offset_x = -top_r_x;
- }
- if(angle >= 3.14 && angle < (3*3.14)/2 ){
- offset_y = -bot_l_y;
- offset_x = -bot_r_x;
- }
- if(angle >= (3*3.14)/2 && angle < 2*3.14 ){
- offset_x = -bot_l_x;
- }
- int i, i_out, x_in, y_in, x_out, y_out;
- double sinyin =0, cosyin = 0;
- int half_lenght = length>>1; //Divide by 2
- int newLength = outputMatrix.mat.length;
- y_in = -1;
- //Boucle principale
- for(i=0; i<half_lenght; i++){
- x_in = i % width;
- if(x_in == 0){
- y_in++;
- sinyin = y_in*sin;
- cosyin = y_in * cos;
- }
- //y_in = i / width;
- x_out = (int)(x_in * cos+ sinyin) + offset_x ;
- y_out = (int)(x_in * minus_sin + cosyin) + offset_y ;
- i_out = x_out + newWidth*y_out;
- outputMatrix.mat[i_out]=inputMatrix.ARGB[i];
- 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
- if(i%100==0) repaint();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement