
我们可以通过创建fabric.Polygon的实例来创建一个Polygon对象。多边形对象的特征可以是由一组连接的直线段组成的任何闭合形状。由于它是 FabricJS 的基本元素之一,我们还可以通过应用角度、不透明度等属性轻松自定义它。为了找到表示当前变换的变换矩阵,我们使用 calcOwnMatrix 方法。
语法
calcOwnMatrix(): Array
示例 1:使用 calcOwnMatrix 方法
让我们看一个代码示例,了解如何使用 calcOwnMatrix 方法找到表示多边形当前变换的变换矩阵。您可以从开发工具打开控制台来查看正在显示的数组值。
Using the calcOwnMatrix method
You can open console from dev tools and see that the logged output contains the transform matrix of the polygon instance
示例 2:使用 calcOwnMatrix 方法和 ScaleX 属性
让我们看一个代码示例,以了解当我们对多边形对象应用水平缩放时,返回数组的值是如何受到影响的。在这里,我们向scaleX属性传递了值2。这确保了我们的多边形对象在水平方向上缩放2倍。我们还可以在控制台中看到返回数组的第0个索引值发生了变化。这是因为第 0 个索引表示scaleX 值。
Using the calcOwnMatrix method along with scaleX property
You can open console from dev tools and see that the logged output has changed
结论
在本教程中,我们使用两个简单的示例来演示如何使用 FabricJS 找到表示 Polygon 对象当前变换的变换矩阵。










