Qt 座標系統 筆記

來源:互聯網
上載者:User

座標變換

World Corrdinates

==>

Window Coordinates

==>

Device Coordinates

(邏輯座標)

世界變換

中間態座標

視窗視口變換

(物理座標)

在預設情況下,3個座標系是一致的。

世界變換

世界變換直接相關的函數:

QPainter::setWorldMatrixEnabled

啟用、禁用世界變換

QPainter::setWorldTransform

設定世界變換

QPainter::worldTransform

擷取當前

QPainter::resetTransform

重設為 QTransform()

4個常用的函數

  • QPainter::scale
  • QPainter::shear
  • QPainter::rotate
  • QPainter::translate

註:它們通過直接調用的 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' }

相關(有待學習):

射影幾何學、仿射幾何學、歐氏幾何學

參考
  • http://doc.qt.nokia.com/4.7/qtransform.html

  • http://doc.qt.nokia.com/4.7/qpainter.html

  • http://doc.qt.nokia.com/4.7/coordsys.html

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.