Scaling a QPolygon or QPolygonF

蓝咒 提交于 2019-12-11 07:03:46

问题


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


回答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.



来源:https://stackoverflow.com/questions/6900006/scaling-a-qpolygon-or-qpolygonf

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