我有以下 JSFiddle http://jsfiddle.net/3vf9J/突出了我的问题。
我遵循了有关如何制作将 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进行矩阵数学运算(乘法)