FabricJs和Polygon转换后的坐标 [英] FabricJs and Polygon transformed coordinates

查看:664
本文介绍了FabricJs和Polygon转换后的坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们是Fabric.js的新手.我们正在使用它在画布上绘制真实场景中的多边形.我们需要移动,旋转多边形并调整其大小,然后重新获得veterxes坐标.

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.

转换后,我们使用了API.

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?

试图获取多边形的transformMatrix,但它为null.即使我们有了矩阵,我们如何应用它?

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

推荐答案

要点是所有多边形的点都具有到画布的绝对坐标.为了获得实际的点坐标,您必须执行一些转换.这是必需的,因为可能会对多边形应用了一些移动和/或变换.

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.

查看以下答案: https://stackoverflow.com/a/53710375/4681279

这篇关于FabricJs和Polygon转换后的坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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