我有以下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做我的矩阵数学(倍增)