Doc: Improve QTransform documentation
* Explain QTransform's model of vector/matrix operations. * Improve snippets used to illuminate QTransform's behavior. Fixes: QTBUG-83869 Change-Id: I84c3b1a221c139ee992f82c3ee4aebadeef8ee63 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Topi Reiniö <topi.reinio@qt.io> Reviewed-by: Andy Nichols <andy.nichols@qt.io> (cherry picked from commit ae2ef9dbf060ba101e32bae2b5edfed979630e30) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
3d512d1756
commit
1bdd0cb3a7
@ -54,7 +54,7 @@ namespace src_gui_painting_qtransform {
|
|||||||
//! [0]
|
//! [0]
|
||||||
x' = m11*x + m21*y + dx
|
x' = m11*x + m21*y + dx
|
||||||
y' = m22*y + m12*x + dy
|
y' = m22*y + m12*x + dy
|
||||||
if (is not affine) {
|
if (!isAffine()) {
|
||||||
w' = m13*x + m23*y + m33
|
w' = m13*x + m23*y + m33
|
||||||
x' /= w'
|
x' /= w'
|
||||||
y' /= w'
|
y' /= w'
|
||||||
@ -65,7 +65,7 @@ if (is not affine) {
|
|||||||
//! [1]
|
//! [1]
|
||||||
x' = m11*x + m21*y + dx
|
x' = m11*x + m21*y + dx
|
||||||
y' = m22*y + m12*x + dy
|
y' = m22*y + m12*x + dy
|
||||||
if (is not affine) {
|
if (!isAffine()) {
|
||||||
w' = m13*x + m23*y + m33
|
w' = m13*x + m23*y + m33
|
||||||
x' /= w'
|
x' /= w'
|
||||||
y' /= w'
|
y' /= w'
|
||||||
@ -76,7 +76,7 @@ if (is not affine) {
|
|||||||
//! [2]
|
//! [2]
|
||||||
x' = m11*x + m21*y + dx
|
x' = m11*x + m21*y + dx
|
||||||
y' = m22*y + m12*x + dy
|
y' = m22*y + m12*x + dy
|
||||||
if (is not affine) {
|
if (!isAffine()) {
|
||||||
w' = m13*x + m23*y + m33
|
w' = m13*x + m23*y + m33
|
||||||
x' /= w'
|
x' /= w'
|
||||||
y' /= w'
|
y' /= w'
|
||||||
@ -87,7 +87,7 @@ if (is not affine) {
|
|||||||
//! [3]
|
//! [3]
|
||||||
x' = m11*x + m21*y + dx
|
x' = m11*x + m21*y + dx
|
||||||
y' = m22*y + m12*x + dy
|
y' = m22*y + m12*x + dy
|
||||||
if (is not affine) {
|
if (!isAffine()) {
|
||||||
w' = m13*x + m23*y + m33
|
w' = m13*x + m23*y + m33
|
||||||
x' /= w'
|
x' /= w'
|
||||||
y' /= w'
|
y' /= w'
|
||||||
|
@ -48,6 +48,7 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QMath>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
@ -105,18 +106,15 @@ class BasicOperations : public QWidget
|
|||||||
//! [2]
|
//! [2]
|
||||||
void BasicOperations::paintEvent(QPaintEvent *)
|
void BasicOperations::paintEvent(QPaintEvent *)
|
||||||
{
|
{
|
||||||
double pi = 3.14;
|
const double a = qDegreesToRadians(45.0);
|
||||||
|
|
||||||
double a = pi/180 * 45.0;
|
|
||||||
double sina = sin(a);
|
double sina = sin(a);
|
||||||
double cosa = cos(a);
|
double cosa = cos(a);
|
||||||
|
|
||||||
QTransform translationTransform(1, 0, 0, 1, 50.0, 50.0);
|
QTransform scale(0.5, 0, 0, 1.0, 0, 0);
|
||||||
QTransform rotationTransform(cosa, sina, -sina, cosa, 0, 0);
|
QTransform rotate(cosa, sina, -sina, cosa, 0, 0);
|
||||||
QTransform scalingTransform(0.5, 0, 0, 1.0, 0, 0);
|
QTransform translate(1, 0, 0, 1, 50.0, 50.0);
|
||||||
|
|
||||||
QTransform transform;
|
QTransform transform = scale * rotate * translate;
|
||||||
transform = scalingTransform * rotationTransform * translationTransform;
|
|
||||||
|
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
painter.setPen(QPen(Qt::blue, 1, Qt::DashLine));
|
painter.setPen(QPen(Qt::blue, 1, Qt::DashLine));
|
||||||
|
@ -213,6 +213,7 @@ static void nanWarning(const char *func)
|
|||||||
transformation is achieved by setting both the projection factors and
|
transformation is achieved by setting both the projection factors and
|
||||||
the scaling factors.
|
the scaling factors.
|
||||||
|
|
||||||
|
\section2 Combining Transforms
|
||||||
Here's the combined transformations example using basic matrix
|
Here's the combined transformations example using basic matrix
|
||||||
operations:
|
operations:
|
||||||
|
|
||||||
@ -223,6 +224,26 @@ static void nanWarning(const char *func)
|
|||||||
\snippet transform/main.cpp 2
|
\snippet transform/main.cpp 2
|
||||||
\endtable
|
\endtable
|
||||||
|
|
||||||
|
The combined transform first scales each operand, then rotates it, and
|
||||||
|
finally translates it, just as in the order in which the product of its
|
||||||
|
factors is written. This means the point to which the transforms are
|
||||||
|
applied is implicitly multiplied on the left with the transform
|
||||||
|
to its right.
|
||||||
|
|
||||||
|
\section2 Relation to Matrix Notation
|
||||||
|
The matrix notation in QTransform is the transpose of a commonly-taught
|
||||||
|
convention which represents transforms and points as matrices and vectors.
|
||||||
|
That convention multiplies its matrix on the left and column vector to the
|
||||||
|
right. In other words, when several transforms are applied to a point, the
|
||||||
|
right-most matrix acts directly on the vector first. Then the next matrix
|
||||||
|
to the left acts on the result of the first operation - and so on. As a
|
||||||
|
result, that convention multiplies the matrices that make up a composite
|
||||||
|
transform in the reverse of the order in QTransform, as you can see in
|
||||||
|
\l {Combining Transforms}. Transposing the matrices, and combining them to
|
||||||
|
the right of a row vector that represents the point, lets the matrices of
|
||||||
|
transforms appear, in their product, in the order in which we think of the
|
||||||
|
transforms being applied to the point.
|
||||||
|
|
||||||
\sa QPainter, {Coordinate System}, {painting/affine}{Affine
|
\sa QPainter, {Coordinate System}, {painting/affine}{Affine
|
||||||
Transformations Example}, {Transformations Example}
|
Transformations Example}, {Transformations Example}
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user