Boa noite caros!
Seguinte: preciso rotacionar um retângulo no seu eixo, mas apenas usar a API Graphics, nao posso usar a Graphics2D. Não estou conseguindo, o desenho rotacionado é pintado longe ou de forma diferente do quadrado, veja o método do main:
rad = 45; // aqui depois vou colocar para o usuário informar o ângulo, pode ser qualquer um.
cos = Math.cos(Math.toRadians(rad));
sen = Math.sin(Math.toRadians(rad));
x1 = Math.abs((int) (xRetRot1*cos - yRetRot1*sen));
y1 = Math.abs((int) (yRetRot1*sen + xRetRot1*cos));
x2 = Math.abs((int) (xRetRot2*cos - yRetRot2*sen));
y2 = Math.abs((int) (yRetRot2*sen + xRetRot2*cos));
x3 = Math.abs((int) (xRetRot3*cos - yRetRot3*sen));
y3 = Math.abs((int) (yRetRot3*sen + xRetRot3*cos));
x4 = Math.abs((int) (xRetRot4*cos - yRetRot4*sen));
y4 = Math.abs((int) (yRetRot4*sen + xRetRot4*cos));
((Desenha)this.jPanel3).rotacaoQuadrado(x1,y1,x2,y2,x3,y3,x4,y4);
/*xRetRot1 = 400; yRetRot1 = 290; xRetRot2 = 400; yRetRot2 = 190; coodernadas do retângulo na sua posição inicial
xRetRot3 = 500; yRetRot3 = 190; xRetRot4 = 500; yRetRot4 = 290;*/
Aqui o método rotacaoQuadrado():
public void rotacaoQuadrado(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4){
Graphics g = (Graphics) this.getGraphics();
int ValoresX[] = {x1, x2, x3, x4};
int ValoresY[] = {y1, y2, y3, y4};
g.setColor(Color.ORANGE);
g.drawPolygon(ValoresX,ValoresY,4);
}
Se alguém puder me ajudar, agradecido.