Qt坐标系统
发布日期:2022-03-12 04:49:19 浏览次数:40 分类:技术文章

本文共 1590 字,大约阅读时间需要 5 分钟。

坐标变换

World Corrdinates

==>

Window Coordinates

==>

Device Coordinates

(逻辑坐标)

世界变换

中间态坐标

窗口视口变换

(物理坐标)

在默认情况下,3个坐标系是一致的。

世界变换

世界变换直接相关的函数:

QPainter::setWorldMatrixEnabled

启用、禁用世界变换

QPainter::setWorldTransform

设置世界变换

QPainter::worldTransform

获取当前

QPainter::resetTransform

重置为 QTransform()

4个常用的函数

QPainter::translate

平移

QPainter::scale

缩放

QPainter::rotate

旋转

QPainter::shear

剪切

注:它们通过直接调用的 QTransform 的相应成员直接修改世界变换

void QPainter::scale(qreal sx, qreal sy)

{
    ...
    d->state->worldMatrix.scale(sx,sy);
    ...
}

世界变换的两个马甲:

QPainter::setTransform

QPainter::transform

void QPainter::setTransform(const QTransform &transform, bool combine )

{

    setWorldTransform(transform, combine);

}

废弃的函数(Qt4.3开始,QTransform 取代了QMatrix 的位置,下列函数已不建议使用)

QPainter::setWorldMatrix

QPainter::worldMatrix

...

窗口视口变换

直接相关:

QPainter::setViewTransformEnabled

启用、禁用 视口变换

QPainter::viewTransformEnabled

返回 视口变换的状态 

QPainter::setViewport

设置 视口(物理坐标)

QPainter::setWindow

设置 窗口(与视口是同一矩形,中间态坐标)

该变换是简单的线性变换。

复合变换

窗口视口变换和世界变换的复合:

QPainter::combinedTransform

QTransform QPainter::combinedTransform() const

{

    Q_D(const QPainter);
    return d->state->worldMatrix * d->viewTransform();

}

典型应用:对鼠标事件的响应中,将坐标从物理坐标变换成QPainter需要的逻辑坐标

仿射变换、透射变换

Qt4.3(包括)之前的 QMatrix 只支持仿射变换(Affine transformation)

平移(Translation)

缩放(Scale

旋转(Rotation

剪切(Shear)

QTransform 支持透射变换(perspective transformation)

m11

m12

m13

m21

m22

m23

m31 

dx

m32 

dy

m33

变换关系:

x' = m11*x + m21*y + dx

 y' = m22*y + m12*x + dy
 if (is not affine)

{

     w' = m13*x + m23*y + m33
     x' /= w'
     y' /= w'

}

 

相关知识:

、、

参考

 

转载于:https://www.cnblogs.com/springmvc-hibernate/archive/2011/06/27/2484115.html

转载地址:https://blog.csdn.net/weixin_30348519/article/details/98108135 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:sql语句分析点滴
下一篇:三级联动

发表评论

最新留言

网站不错 人气很旺了 加油
[***.192.178.218]2024年04月02日 10时55分59秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章

LeetCode题解(0736):Lisp语法表达式解析(Python) 2019-04-26
LeetCode题解(0761):特殊的二进制序列交换后的最大值(Python) 2019-04-26
LeetCode题解(0767):重构字符串至相邻字符不相同(Python) 2019-04-26
LeetCode题解(0791):依据字符在另一个字符串中的出现顺序排序字符串(Python) 2019-04-26
LeetCode题解(0809):判断字符串是否由单词扩张形成(Python) 2019-04-26
LeetCode题解(0816):模糊坐标(Python) 2019-04-26
LeetCode题解(0831):隐藏邮箱地址和电话号码个人信息(Python) 2019-04-26
LeetCode题解(0833):字符串中的查找与替换(Python) 2019-04-26
LeetCode题解(0842):将数组拆分成斐波那契数列(Python) 2019-04-26
LeetCode题解(0848):字母逐个移位转换(Python) 2019-04-26
LeetCode题解(0890):字符串的模式查找(Python) 2019-04-26
LeetCode题解(0899):计算移动后字典序最小的序列(Python) 2019-04-26
LeetCode题解(0916):判断单词是否包含指定多个子集(Python) 2019-04-26
LeetCode题解(0936):序列能否由指定印章印成(Python) 2019-04-26
LeetCode题解(0966):多条件的元音拼写检查器(Python) 2019-04-26
LeetCode题解(1016):判断大量整数的二进制表示是否为字符串的子串(Python) 2019-04-26
LeetCode题解(1023):判断字符串是否能通过模式串添加小写字母生成(Python) 2019-04-26
LeetCode题解(1081):不同字符的最小子序列(Python) 2019-04-26
LeetCode题解(1096):按照指定语法展开字符串的花括号(Python) 2019-04-26
LeetCode题解(1106):解析字符串表示的布尔表达式(Python) 2019-04-26