Girar libreria java
Enviado por juan noe • 9 de Enero de 2019 • Apuntes • 530 Palabras (3 Páginas) • 144 Visitas
public static float[][] rotarAngInv(float[][] im1,float ang){
int filas=(int)(im1.length),cols=(int)(im1[0].length);
int xIzq=0,yIzq=filas, xDer=cols, yDer=0;
int xSup=0, ySup=0 ,xInf=cols, yInf=filas;
int nX,nY;
//double cosa=Math.cos(Math.toRadians(ang)),sena=Math.sin(Math.toRadians(ang));
float c=(float)Math.cos(Math.toRadians(ang)), s=(float)Math.sin(Math.toRadians(ang)),
xP=cols/2, yP=filas/2,
r11=c,r12=s,
r21=-s,r22=c,
r31=-xP*c+yP*s+xP,r32=-xP*s-yP*c+yP;
int x1=(int)(xIzq*r11+yIzq*r21+r31);
int x2=(int)(xDer*r11+yDer*r21+r31);
int y1=(int)(xSup*r12+ySup*r22+r32);
int y2=(int)(xInf*r12+yInf*r22+r32);
int ancho=(int)Math.abs(x2-x1);
int alto= (int)Math.abs(y2-y1);
float[][] asal= new float[alto][ancho];
c=(float)Math.cos(Math.toRadians(-ang));
s=(float)Math.sin(Math.toRadians(-ang));
xP=ancho/2; yP=alto/2;
r11=c;r12=s;
r21=-s;r22=c;
r31=-xP*c+yP*s+xP;
r32=-xP*s-yP*c+yP;
for(int i=0;i<alto;i++){
for(int j=0;j<ancho;j++){
nX=(int)(j*r11+i*r21+r31)+x1;
nY=(int)(j*r12+i*r22+r32)+y1;
if((nX >=0 && nX<cols)&&(nY>=0 && nY<filas))
asal[i][j]=im1[nY][nX];
}
}
return asal;
}
...