了解Qt的QTransform旋转功能 [英] Understanding Qt's QTransform rotate function

查看:824
本文介绍了了解Qt的QTransform旋转功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

​​这个问题的结果,我想了解更多有关Qt的 QTransform :: rotate 函数的信息。 在文档中说:

As a result of this question, I'd like to understand more about Qt's QTransform::rotate function. In the documentation, it says:


QTransform& QTransform :: rotate(qreal angle,Qt :: Axis axis = Qt :: ZAxis)

QTransform & QTransform::rotate ( qreal angle, Qt::Axis axis = Qt::ZAxis )

以指定角度围绕指定轴逆时针旋转坐标系并返回a

Rotates the coordinate system counterclockwise by the given angle about the specified axis and returns a reference to the matrix.

请注意,如果将QTransform应用于小部件坐标中定义的点,则旋转方向将为顺时针,因为y轴指向下方

Note that if you apply a QTransform to a point defined in widget coordinates, the direction of the rotation will be clockwise because the y-axis points downwards.

角度以度为单位。

来自上一个问题,我了解到要根据 rotate QPolygonF ,实际上我必须将其逆时针旋转90度。 >函数:

From my previous question, I learned that to rotate a QPolygonF clockwise, I must actually rotate it 90 degrees counter-clockwise, according to the rotate function:

QPolygonF original = QPolygonF() << QPoint(0, 1) << QPoint(4, 1) << QPoint(4, 2) << QPoint(0, 2);
QTransform transform = QTransform().translate(2, 2).rotate(90).translate(-2, -2);
QPolygonF rotated = transform.map(original);
qDebug() << rotated;

输出:

QPolygonF(QPointF(3, 0) QPointF(3, 4) QPointF(2, 4) QPointF(2, 0) ) 

例如为此矩形:

要旋转到此处:

这是为什么?为什么文档说我对 QTransform :: rotate 的调用实际上导致顺时针旋转,当我认为我不在小部件坐标中时-没有任何小部件

Why is this? Why does the documentation say that my call to QTransform::rotate is actually causing a clockwise rotation when I believe I'm not in "widget coordinates" - there are no widgets involved here.

推荐答案

QTransform在数学笛卡尔坐标系中运行。即。右上象限是正x和正y一(象限1)。您的图表位于y轴翻转小部件坐标中,象限1位于右下角。

QTransform operates in mathematical Cartesian coordinate system. ie. the top-right quadrant is the positive-x and positive-y one (quadrant 1). Your chart is in the y-axis-flipped Widget coordinates with quadrant 1 at lower-right.

旋转确实会逆时针旋转。但是由于Y轴在Widget坐标中翻转,所以它变为顺时针。

Rotate does rotate counterclockwise. But since Y-axis is flipped in Widget coordinates, it becomes clockwise.

正如您提到的,多边形与Widget无关。它确实会旋转CCW,但是您正在使用小部件坐标对其进行可视化。

As you mentioned, polygon has nothing to do with widgets. It does rotate CCW, but you are visualizing it with widget coordinates.

这篇关于了解Qt的QTransform旋转功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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