How do i get point coordinates after object modified?

对着背影说爱祢 提交于 2019-12-08 04:11:47

问题


I would like to get the new point coordinates after object being modified but when i get the points coordinates after being modified they are the same point coordinates with which I have drawn the polygon. Can anyone please tell me why it so? Below is my code,

<!--fabricjs -->
canvas.on('object:modified', function(e){

 var obj=e.target;
 console.log("new point coordinates "+obj.points);
});

回答1:


Below is the code I used to get the updated points with ROTATE being disabled. But if I get the updated points using below code with rotate option being enabled and after rotating the object, I get wrong set of points , so for now I have disabled the rotate option. It will be great help if any one could say how can I modify below code to have the rotate option enabled and get right set of points.

<!-- fabric js -->
        canvas.on('object:modified', function(e) {
                var newCoordinates = "";
                var matrix = [];
                var polygon = canvas.getItemById(e.target.id);
                matrix = polygon.calcTransformMatrix();
                var translatedPoints = polygon.get('points').map(function(p) {
                    return {
                        x: p.x - polygon.pathOffset.x,
                        y: p.y - polygon.pathOffset.y
                    };
                });
                for (var i = 0; i < translatedPoints.length; i++) {
                    translatedPoints[i].x = matrix[0] * translatedPoints[i].x + matrix[2] * translatedPoints[i].y + matrix[4];
                    translatedPoints[i].y = matrix[1] * translatedPoints[i].x + matrix[3] * translatedPoints[i].y + matrix[5];
                }
                var newUpdatedPoints = JSON.stringify(translatedPoints);
            });


来源:https://stackoverflow.com/questions/38567332/how-do-i-get-point-coordinates-after-object-modified

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