我有以下JSFiddle http://jsfiddle.net/3vf9J/這突出了我的問題。CSS matrix3d計算不正確,但爲什麼?
我跟着就如何使一個函數來CSS結合導向轉變成一個Matrix3D這樣我就可以比蘋果每次一個多。
不幸的是我無法正常工作。圍繞一個軸簡單旋轉180度,最終看起來更像135度,所以我清楚地發現一些數學錯誤。
能理解矩陣的人能幫助我嗎?
我的功能看起來是這樣的:
var generateRotationMatrix = function(x, y, z, tx, ty, tz) {
var a = x;
var b = y;
var c = z;
var rotationXMatrix = $M([
[1,0,0,0],
[0,Math.cos(a), Math.sin(-a), 0],
[0,Math.sin(a), Math.cos(a), 0],
[0,0,0,1]
]);
var rotationYMatrix = $M([
[Math.cos(b), 0, Math.sin(b),0],
[0,1,0,0],
[Math.sin(-b), 0, Math.cos(b), 0],
[0,0,0,1]
]);
var rotationZMatrix = $M([
[Math.cos(c), Math.sin(-c), 0, 0],
[Math.sin(c), Math.cos(c), 0, 0],
[0,0,1,0],
[0,0,0,1]
]);
var translationMatrix = $M([
[1,0,0,0],
[0,1,0,0],
[0,0,1,0],
[tx,ty,tz,1]
]);
var tM = rotationXMatrix
.x(rotationYMatrix)
.x(rotationZMatrix)
.x(translationMatrix);
var s = "matrix3d("
s += tM.e(1,1).toFixed(10) + "," + tM.e(1,2).toFixed(10) + "," + tM.e(1,3).toFixed(10) + "," + tM.e(1,4).toFixed(10) + ","
s += tM.e(2,1).toFixed(10) + "," + tM.e(2,2).toFixed(10) + "," + tM.e(2,3).toFixed(10) + "," + tM.e(2,4).toFixed(10) + ","
s += tM.e(3,1).toFixed(10) + "," + tM.e(3,2).toFixed(10) + "," + tM.e(3,3).toFixed(10) + "," + tM.e(3,4).toFixed(10) + ","
s += tM.e(4,1).toFixed(10) + "," + tM.e(4,2).toFixed(10) + "," + tM.e(4,3).toFixed(10) + "," + tM.e(4,4).toFixed(10)
s += ")";
return s;
}
請注意我用Sylvester做我的矩陣數學(倍增)