我想在PVector類中使用heading()函數,但是我使用P3D併爲我的PVector設置了x,y和z。我將如何重新編寫此功能以使其可用於3D空間?我的目標是做這樣的事情:PVector Heading()for 3D Rotation
size(100, 100, P3D);
PVector v = new PVector(.2, .11, .54);
rotate(v.heading()); //set rotation from PVector named v
line(0, 0, 10, 0); //draw line that will be rotated in correct direction
上面的代碼,因爲v.heading不會顯示在三維空間中正確的旋轉()只適用於二維座標空間。我怎樣才能實現這個使用rotateX(),rotateY(),rotateZ()?我想盡可能避免使用四元數並使用旋轉函數。
在此先感謝!
感謝這麼多的響應Kevinsa5。你能指出我將如何在rotateX(),rotateY()和rotateZ()中使用它來使用這些變量實現正確的旋轉。 – Robbie
我試過這個沒有運氣: rotateX(sin(theta)* cos(theta)); rotateY(cos(theta)); (sin(theta)* sin(theta)); – Robbie
......以及:rotateX(rho * sin(phi)* cos(theta)); rotateY(rho * sin(phi)* sin(theta)); rotateZ(rho * cos(phi)); – Robbie