CSS矩阵乘法
根据 WebKitCSSMatrix 文档,multiply() 函数“返回此矩阵乘以 a 的结果给定右侧的矩阵。”。因此,
在数学表示法中,a.multiply(b)
必须等于 a b
。
但看起来a.multiply(b)
确实等于b a
;结果等于左侧给定矩阵的乘积。
举个例子:
设 a:
2, -2, 5, 0
-1, 0, 12, 0
3, 1, -2, 0
0, 0, 0, 1
和 B:
1, 4, 3, 0
3, 1, 5, 0
3, 4, 3, 0
0, 0, 0, 1
使用 这个工具 a b
的乘积
c = a b:
11, 26, 11, 0
35, 44, 33, 0
0, 5, 8, 0
0, 0, 0, 1
在 JavaScript 中是:
a = new WebKitCSSMatrix("matrix3d(2,-2,5,0, -1,0,12,0, 3,1,-2,0, 0,0,0,1)")
b = new WebKitCSSMatrix("matrix3d(1,4,3,0, 3,1,5,0, 3,4,3,0, 0,0,0,1)");
而 a.multiply(b)
是:
7, 1, 47, 0
20, -1, 17, 0
11, -3, 57, 0
0, 0, 0, 1
但实际上 b.multiply(a )
是矩阵c
。
我错过了什么吗?
According to WebKitCSSMatrix documentation, multiply() function "Returns the result of multiplying this matrix by a given matrix that is on the right.". So
a.multiply(b)
must be equal to a b
in math notation.
But it seems that a.multiply(b)
is indeed equal to b a
; the result is equal to the product when the given matrix at the left.
For an example:
Let a:
2, -2, 5, 0
-1, 0, 12, 0
3, 1, -2, 0
0, 0, 0, 1
and B:
1, 4, 3, 0
3, 1, 5, 0
3, 4, 3, 0
0, 0, 0, 1
Using this tool the product of a b
is
c = a b:
11, 26, 11, 0
35, 44, 33, 0
0, 5, 8, 0
0, 0, 0, 1
In JavaScript:
a = new WebKitCSSMatrix("matrix3d(2,-2,5,0, -1,0,12,0, 3,1,-2,0, 0,0,0,1)")
b = new WebKitCSSMatrix("matrix3d(1,4,3,0, 3,1,5,0, 3,4,3,0, 0,0,0,1)");
and a.multiply(b)
is:
7, 1, 47, 0
20, -1, 17, 0
11, -3, 57, 0
0, 0, 0, 1
but actually b.multiply(a)
is matrix c
.
Am I missing anything?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的观察是正确的,但规范的描述也是正确的。您必须注意的是,CSS 规范中定义的矩阵是列优先的,而大多数数学书籍都会以行优先的格式处理矩阵。尝试转换它,看看会发生什么。
You are correct in your observation but the spec is also correct in its description. What you have to observe is that matrices defined in the CSS spec are column-major where as most math books will tackle matrices in row-major format. Try converting it and see what happens.
矩阵乘法是“一般不可交换”,这意味着 a.multiply(b) 通常不可交换与 b.multiply(a) 相同。
Matrix multiplication is "in general not commutative" which means that a.multiply(b) is generally not going to be the same as b.multiply(a).