javascript - Snap.svg - Matrix.add() 如何工作?

标签 javascript svg snap.svg

我无法理解数学上 Matrix.add() 的工作原理,Snap.svg 文档说:

Adds the given matrix to existing one


HTML:

<svg id="svgout" width="1000" height="1000" viewBox="0 0 800 800"></svg> 


JS:

var paper = Snap("#svgout"); 
var r = paper.rect(0,0,100,100);

var mat = new Snap.matrix();
mat.scale(.5);
mat.add(mat.scale(3));

r.attr({transform: mat});
console.log(r.getBBox().width + "  " + r.getBBox().height );


我的问题是:

mat.scale(.5);           // width and height = 50
mat.add(mat.scale(3));   // width and height = 300

所以,最终的宽度和高度应该是 50 + 300 = 350
但console.log中的结果= 225


再次尝试

mat.scale(1);           // width and height = 100
mat.add(mat.scale(3));  // width and height = 300

我的期望:100 + 300 = 400
但控制台中的结果 = 900!

这个demo

最佳答案

之后

mat.scale(.5)

mat 现在是一个比例为 0.5 的矩阵 (s0.5)

然后我们采用 s0.5 矩阵并执行

mat.add(mat.scale(3)) 

原来如此

s1.5.add(s1.5)

1.5 x 1.5 = 2.25

QED

另一个例子是相同的 3 x 3 = 9

关于javascript - Snap.svg - Matrix.add() 如何工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37553625/

相关文章:

javascript - Firebase 云功能中的权限被拒绝

javascript - 可能会破坏我 Javascript 职业生涯的基本 boolean 逻辑

javascript - 如何改变节点的不透明度?

html - 使用 HTML 和 CSS 的 SVG 剪辑路径问题

javascript - 如何在 snapsvg 上将一个元素附加到另一个元素中?

javascript - 如何初始化 - 使用 TypeScript 的 AngularJs 应用程序

javascript - 为 3 <img> 的水平行创建透明覆盖

javascript - 为什么节点包含方法未捕获对 svg 元素的单击?

javascript - 我怎样才能把这个 SVG ‘Sidebar Menu’ 放在右边?

javascript - 如何使用 Snap.svg 在 Karma 中编写与 SVG 图形交互的单元测试?