缩放 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
};
它生成 ---15,120-- ---30,15-- ---120,45-- ---135,105--
因此它也略有移动。
有没有办法从中心缩放? 例如,缩放后形状的原点应该是同一点。 是否有内置方法或者我必须再次计算所有点以进行缩放? 谢谢
I need to scale a polygon.
write the following
Qt Code:
QPolygonF qpf=QPolygonF(QPolygon(4,points));
QTransform trans;
trans=trans.scale(1.5,1.5);
QPolygonF qpf2=trans.map(qpf);
path.addPolygon(qpf2);
for the points:
Qt Code:
static const int points[8] = {
10, 80,
20, 10,
80, 30,
90, 70
};
it generates
---15,120--
---30,15--
---120,45--
---135,105--
thus it moves slightly too.
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
目前,您正在根据“世界”坐标系中的坐标应用比例。这解释了您所看到的行为。您希望将它们应用到本地或“对象”坐标系中。
为了实现您想要的效果,您必须平移多边形,使其中心(或您所说的形状原点)与坐标系的原点对齐(或者更确切地说“成为”)。然后应用您想要的比例,然后应用初始翻译的倒数。
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.