如何在对象修改后获得点坐标? [英] How do i get point coordinates after object modified?

查看:212
本文介绍了如何在对象修改后获得点坐标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在对象被修改后得到新的点坐标,但是当我得到修改后的点坐标,它们是我绘制多边形的相同的点坐标。
任何人都可以告诉我为什么会这样?下面是我的代码,

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);
});


推荐答案

下面是我用来获取更新点其中ROTATE已禁用。
但是如果我得到更新的点使用下面的代码与启用旋转选项和旋转对象后,我得到错误的点集,所以现在我已禁用旋转选项。如果任何人可以说如何修改以下代码以启用轮换选项并获得正确的点集,这将是很大的帮助。

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);
            });

这篇关于如何在对象修改后获得点坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆