我想旋轉一個矩形,而不使用旋轉功能,而是使用矩陣..我知道如何使用矩陣旋轉一條線,但我所有嘗試旋轉矩形都失敗了。處理,使用矩陣旋轉矩形?
我不認爲這是完全使用,但繼承人是我的代碼,旋轉線。
float[][] rotation;
float[] position;
float theta = 180;
float pointX;
float pointY;
void setup() {
frameRate(60);
size(600, 600);
pointX = 0;
pointY = 0;
rotation = new float[2][2];
position = new float[8];
}
void draw() {
background(200);
theta = mouseX;
position[0] = mouseY;
position[1] = mouseY;
position[2] = -mouseY;
position[3] = mouseY;
rotation[0][0] = cos(radians(theta));
rotation[0][1] = -sin(radians(theta));
rotation[1][0] = sin(radians(theta));
rotation[1][1] = cos(radians(theta));
float newpos[] = new float[8];
newpos[0] += position[0] * rotation[0][0];
newpos[1] += position[1] * rotation[0][1];
translate(width/2, height/2);
line(0, 0, pointX+newpos[0], pointY+newpos[1]);
line(0, 0, pointX+newpos[0] * -1, pointY+newpos[1] * -1);
}
任何你不使用android.graphics.Matrix的原因? – Michael
它的學校和老師沒有提到任何關於它......而他不希望我們使用捷徑...... – Mark9135
好吧(雖然如果這是一門編程課程,我是你的老師,我會責怪你製作自己的代碼而不是使用現有的類)。你的矩形代碼在哪裏? – Michael