缩放QPolygon或QPolygonF [英] Scaling a QPolygon or QPolygonF

查看:859
本文介绍了缩放QPolygon或QPolygonF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要缩放多边形.

编写以下内容

Qt代码:

QPolygonF qpf=QPolygonF(QPolygon(4,points));
QTransform trans;
trans=trans.scale(1.5,1.5);
QPolygonF qpf2=trans.map(qpf);
path.addPolygon(qpf2);

要点:

Qt代码:

  static const int points[8] = {
    10, 80,
    20, 10,
    80, 30,
    90, 70
    };

它生成 --- 15120-- --- 30,15-- --- 120,45-- --- 135,105-

it generates ---15,120-- ---30,15-- ---120,45-- ---135,105--

因此它也略微移动.

有没有一种方法可以从中心缩放? 例如,形状的原点在缩放后应为同一点. 有内置的方法还是我必须再次计算所有点以按比例缩放? 谢谢

is there a way to scale from center? for example origin of the shape should be the same point after scaling. is there a built in way or must i calculate all the points again to scale? thanks

推荐答案

当前,您正在相对于世界"坐标系中的坐标应用比例尺.可以解释您所看到的行为.您要在局部或对象"坐标系中应用它们.

Currently you're applying your scale with respect to the coordinates in your "World" coordinate system. Which explains the behavior you're seeing. You want to apply them in the local or "Object" coordinate system.

要实现所需的功能,必须平移多边形,使多边形的中心(或您所说的形状的原点)与坐标系的原点对齐(或成为").然后,应用所需的比例,然后应用初始平移的逆.

To achieve what you want to have you would have to translate the polygon so its center (or origin of the shape as you say) is aligned with (or rather "becomes") the origin of your coordinate system. Then you apply the scale you desire and subsequently apply the inverse of your initial translation.

这篇关于缩放QPolygon或QPolygonF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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