FabricJs and Polygon transformed coordinates

淺唱寂寞╮ 提交于 2020-01-05 04:07:07

问题


We're new to Fabric.js. We're using it to draw polygons on our canvas in overlay on a real scene. We need to move, to rotate and resize the polygon and then get back the veterxes coordinates.

After the transformation we used the API.

var originalPolyPoints = pol.get('points').map(function (p) 
{
    return {x: p.x , y: p.y };
});

This way, the coordinates are always the original but not the changed ones. How can we get the new coordinates?

Tried to get the transformMatrix of the polygon, but it was null. Even if we have the matrix, how can we apply it?


回答1:


I think maybe you need to call setCoords on the objects after you modify them. This is a purposeful abstraction leak for performance reasons, according to the documentation.




回答2:


The point is that all polygon's points have absolute coordinates to the canvas. In order to get actual points coordinates, you have to perform some transformation. It's required because there could be some movements and/or transformations applied to the polygon.

Check out the following answer: https://stackoverflow.com/a/53710375/4681279



来源:https://stackoverflow.com/questions/37722343/fabricjs-and-polygon-transformed-coordinates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!