📄 qwmatrix.3qt
字号:
'\" t.TH QWMatrix 3qt "11 October 2001" "Trolltech AS" \" -*- nroff -*-.\" Copyright 1992-2001 Trolltech AS. All rights reserved. See the.\" license file included in the distribution for a complete license.\" statement..\".ad l.nh.SH NAMEQWMatrix \- 2D transformations of a coordinate system.PP\fC#include <qwmatrix.h>\fR.PP.SS "Public Members".in +1c.ti -1c.BI "\fBQWMatrix\fR ()".br.ti -1c.BI "\fBQWMatrix\fR ( double m11, double m12, double m21, double m22, double dx, double dy )".br.ti -1c.BI "void \fBsetMatrix\fR ( double m11, double m12, double m21, double m22, double dx, double dy )".br.ti -1c.BI "double \fBm11\fR () const".br.ti -1c.BI "double \fBm12\fR () const".br.ti -1c.BI "double \fBm21\fR () const".br.ti -1c.BI "double \fBm22\fR () const".br.ti -1c.BI "double \fBdx\fR () const".br.ti -1c.BI "double \fBdy\fR () const".br.ti -1c.BI "void \fBmap\fR ( int x, int y, int * tx, int * ty ) const".br.ti -1c.BI "void \fBmap\fR ( double x, double y, double * tx, double * ty ) const".br.ti -1c.BI "QRect \fBmapRect\fR ( const QRect & rect ) const".br.ti -1c.BI "QPoint map ( const QPoint & p ) const \fI(obsolete)\fR".br.ti -1c.BI "QRect map ( const QRect & r ) const \fI(obsolete)\fR".br.ti -1c.BI "QPointArray map ( const QPointArray & a ) const \fI(obsolete)\fR".br.ti -1c.BI "void \fBreset\fR ()".br.ti -1c.BI "bool \fBisIdentity\fR () const".br.ti -1c.BI "QWMatrix & \fBtranslate\fR ( double dx, double dy )".br.ti -1c.BI "QWMatrix & \fBscale\fR ( double sx, double sy )".br.ti -1c.BI "QWMatrix & \fBshear\fR ( double sh, double sv )".br.ti -1c.BI "QWMatrix & \fBrotate\fR ( double a )".br.ti -1c.BI "bool \fBisInvertible\fR () const".br.ti -1c.BI "QWMatrix \fBinvert\fR ( bool * invertible = 0 ) const".br.ti -1c.BI "bool \fBoperator==\fR ( const QWMatrix & m ) const".br.ti -1c.BI "bool \fBoperator!=\fR ( const QWMatrix & m ) const".br.ti -1c.BI "QWMatrix & \fBoperator*=\fR ( const QWMatrix & m )".br.ti -1c.BI "QPoint \fBoperator*\fR ( const QPoint & p ) const".br.ti -1c.BI "QRegion \fBoperator*\fR ( const QRect & r ) const".br.ti -1c.BI "QRegion \fBoperator*\fR ( const QRegion & r ) const".br.ti -1c.BI "QPointArray \fBoperator*\fR ( const QPointArray & a ) const".br.in -1c.SH RELATED FUNCTION DOCUMENTATION.in +1c.ti -1c.BI "QWMatrix \fBoperator*\fR ( const QWMatrix & m1, const QWMatrix & m2 )".br.ti -1c.BI "QDataStream & \fBoperator<<\fR ( QDataStream & s, const QWMatrix & m )".br.ti -1c.BI "QDataStream & \fBoperator>>\fR ( QDataStream & s, QWMatrix & m )".br.in -1c.SH DESCRIPTIONThe QWMatrix class specifies 2D transformations of a coordinate system..PPThe standard coordinate system of a paint device has the origin located at the top-left position. X values increase to the right; Y values increase downward..PPThis coordinate system is default for the QPainter, which renders graphics in a paint device. A user-defined coordinate system can be specified by setting a QWMatrix for the painter..PPExample:.PP.nf.br MyWidget::paintEvent( QPaintEvent * ).br {.br QPainter p; // our painter.br QWMatrix m; // our transformation matrix.br m.rotate( 22.5 ); // rotated coordinate system.br p.begin( this ); // start painting.br p.setWorldMatrix( m ); // use rotated coordinate system.br p.drawText( 30,20, "detator" ); // draw rotated text at 30,20.br p.end(); // painting done.br }.br.fi.PPA matrix specifies how to translate, scale, shear or rotate the graphics; the actual transformation is performed by the drawing routines in QPainter and by QPixmap::xForm()..PPThe QWMatrix class contains a 3*3 matrix of the form:.PP.nf.br m11 m12 0.br m21 m22 0.br dx dy 1.br.fi.PPA matrix transforms a point in the plane to another point:.PP.nf.br x' = m11*x + m21*y + dx.br y' = m22*y + m12*x + dy.br.fi.PPThe point \fI(x, y)\fR is the original point, and \fI(x', y')\fR is the transformed point. \fI(x', y')\fR can be transformed back to \fI(x, y)\fR by performing the same operation on the inverted matrix..PPThe elements \fIdx\fR and \fIdy\fR specify horizontal and vertical translation. The elements \fIm11\fR and \fIm22\fR specify horizontal and vertical scaling. The elements \fIm12\fR and \fIm21\fR specify horizontal and vertical shearing..PPThe identity matrix has \fIm11\fR and \fIm22\fR set to 1; all others are set to 0. This matrix maps a point to itself..PPTranslation is the simplest transformation. Setting \fIdx\fR and \fIdy\fR will move the coordinate system \fIdx\fR units along the X axis and \fIdy\fR units along the Y axis..PPScaling can be done by setting \fIm11\fR and \fIm22\fR. For example, setting \fIm11\fR to 2 and \fIm22\fR to 1.5 will double the height and increase the width by 50%..PPShearing is controlled by \fIm12\fR and \fIm21\fR. Setting these elements to values different from zero will twist the coordinate system..PPRotation is achieved by carefully setting both the shearing factors and the scaling factors. The QWMatrix has a function that sets rotation directly..PPQWMatrix lets you combine transformations like this:.PP.nf.br QWMatrix m; // identity matrix.br m.translate(10, -20); // first translate (10,-20).br m.rotate(25); // then rotate 25 degrees.br m.scale(1.2, 0.7); // finally scale it.br.fi.PPHere's the same example using basic matrix operations:.PP.nf.br double a = pi/180 * 25; // convert 25 to radians.br double sina = sin(a);.br double cosa = cos(a);.br QWMatrix m1(0, 0, 0, 0, 10, -20); // translation matrix.br QWMatrix m2( cosa, sina, // rotation matrix.br -sina, cosa, 0, 0 );.br QWMatrix m3(1.2, 0, 0, 0.7, 0, 0); // scaling matrix.br QWMatrix m;.br m = m3 * m2 * m1; // combine all transformations.br.fi.PPQPainter has functions to translate, scale, shear and rotate the coordinate system without using a QWMatrix. Although these functions are very convenient, it can be more efficient to build a QWMatrix and call QPainter::setWorldMatrix() if you want to perform more than a single transform operation..PPSee also QPainter::setWorldMatrix(), QPixmap::xForm(), Graphics Classes and Image Processing Classes..SH MEMBER FUNCTION DOCUMENTATION.SH "QWMatrix::QWMatrix ()"Constructs an identity matrix. All elements are set to zero except \fIm11\fR and \fIm22\fR (scaling), which are set to 1..SH "QWMatrix::QWMatrix ( double m11, double m12, double m21, double m22, double dx, double dy )"Constructs a matrix with the elements, \fIm11\fR, \fIm12\fR, \fIm21\fR, \fIm22\fR, \fIdx\fR and \fIdy\fR..SH "double QWMatrix::dx () const"Returns the horizontal translation..SH "double QWMatrix::dy () const"Returns the vertical translation..SH "QWMatrix QWMatrix::invert ( bool * invertible = 0 ) const"Returns the inverted matrix..PPIf the matrix is singular (not invertible), the identity matrix is returned..PPIf \fIinvertible\fR is not null, the value of \fI*invertible\fR is set to TRUE if the matrix is invertible or to FALSE if the matrix is not invertible..PPSee also isInvertible()..PPExample: t14/cannon.cpp..SH "bool QWMatrix::isIdentity () const"Returns TRUE if the matrix is the identity matrix; otherwise returns FALSE..PPSee also reset()..SH "bool QWMatrix::isInvertible () const"Returns TRUE if the matrix is invertible; otherwise returns FALSE..PPSee also invert()..SH "double QWMatrix::m11 () const"Returns the X scaling factor..SH "double QWMatrix::m12 () const"Returns the vertical shearing factor..SH "double QWMatrix::m21 () const"Returns the horizontal shearing factor..SH "double QWMatrix::m22 () const"Returns the Y scaling factor..SH "void QWMatrix::map ( int x, int y, int * tx, int * ty ) const"Transforms ( \fIx\fR, \fIy\fR ) to ( \fI*tx\fR, \fI*ty\fR ) using the formulae:.PP.nf.br *tx = m11*x + m21*y + dx (rounded to the nearest integer).br *ty = m22*y + m12*x + dy (rounded to the nearest integer).br.fi.PPExamples:.)l t14/cannon.cpp and xform/xform.cpp..SH "void QWMatrix::map ( double x, double y, double * tx, double * ty ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPTransforms ( \fIx\fR, \fIy\fR ) to ( \fI*tx\fR, \fI*ty\fR ) using the following formulae:.PP.nf.br *tx = m11*x + m21*y + dx.br *ty = m22*y + m12*x + dy.br.fi.SH "QPoint QWMatrix::map ( const QPoint & p ) const"\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code..PPDoes the same as operator *( const QPoint &).SH "QRect QWMatrix::map ( const QRect & r ) const"\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code..PPPlease use QWMatrix::mapRect() instead..PPNote that this method does return the bounding rectangle of the \fIr\fR, when shearing or rotations are used..SH "QPointArray QWMatrix::map ( const QPointArray & a ) const"\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code..PPDoes the same as operator *( const QPointArray &).SH "QRect QWMatrix::mapRect ( const QRect & rect ) const"Returns the transformed rectangle \fIrect\fR..PPThe bounding rectangle is returned if rotation or shearing has been specified..PPIf you need to know the exact region \fIrect\fR maps to use operator*()..PPSee also operator*()..SH "bool QWMatrix::operator!= ( const QWMatrix & m ) const"Returns TRUE if this matrix is not equal to \fIm\fR; otherwise returns FALSE..SH "QPoint QWMatrix::operator* ( const QPoint & p ) const"Transforms \fIp\fR to using the formulae:.PP.nf.br retx = m11*px + m21*py + dx (rounded to the nearest integer).br rety = m22*py + m12*px + dy (rounded to the nearest integer).br.fi.SH "QRegion QWMatrix::operator* ( const QRect & r ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPTransforms the rectangle \fIr\fR..PPRotation and shearing a rectangle results in a more general region, which is returned here..PPCalling this method can be rather expensive, if rotations or shearing are used. If you just need to know the bounding rectangle of the returned region, use mapRect() which is a lot faster than this function..PPSee also QWMatrix::mapRect()..SH "QRegion QWMatrix::operator* ( const QRegion & r ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPTransforms the region \fIr\fR..PPCalling this method can be rather expensive, if rotations or shearing are used..SH "QPointArray QWMatrix::operator* ( const QPointArray & a ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPReturns the point array \fIa\fR transformed by calling map for each point..SH "QWMatrix & QWMatrix::operator*= ( const QWMatrix & m )"Returns the result of multiplying this matrix with matrix \fIm\fR..SH "bool QWMatrix::operator== ( const QWMatrix & m ) const"Returns TRUE if this matrix is equal to \fIm\fR; otherwise returns FALSE..SH "void QWMatrix::reset ()"Resets the matrix to an identity matrix..PPAll elements are set to zero, except \fIm11\fR and \fIm22\fR (scaling) that are set to 1..PPSee also isIdentity()..SH "QWMatrix & QWMatrix::rotate ( double a )"Rotates the coordinate system \fIa\fR degrees counterclockwise..PPReturns a reference to the matrix..PPSee also translate(), scale() and shear()..PPExamples:.)l desktop/desktop.cpp, drawdemo/drawdemo.cpp, t14/cannon.cpp and xform/xform.cpp..SH "QWMatrix & QWMatrix::scale ( double sx, double sy )"Scales the coordinate system unit by \fIsx\fR horizontally and \fIsy\fR vertically..PPReturns a reference to the matrix..PPSee also translate(), shear() and rotate()..PPExamples:.)l fileiconview/qfileiconview.cpp, movies/main.cpp, qmag/qmag.cpp, qtimage/qtimage.cpp, showimg/showimg.cpp and xform/xform.cpp..SH "void QWMatrix::setMatrix ( double m11, double m12, double m21, double m22, double dx, double dy )"Sets the matrix elements to the specified values, \fIm11\fR, \fIm12\fR, \fIm21\fR, \fIm22\fR, \fIdx\fR and \fIdy\fR..SH "QWMatrix & QWMatrix::shear ( double sh, double sv )"Shears the coordinate system by \fIsh\fR horizontally and \fIsv\fR vertically..PPReturns a reference to the matrix..PPSee also translate(), scale() and rotate()..PPExamples:.)l drawdemo/drawdemo.cpp and xform/xform.cpp..SH "QWMatrix & QWMatrix::translate ( double dx, double dy )"Moves the coordinate system \fIdx\fR along the X-axis and \fIdy\fR along the Y-axis..PPReturns a reference to the matrix..PPSee also scale(), shear() and rotate()..PPExamples:.)l drawdemo/drawdemo.cpp, t14/cannon.cpp and xform/xform.cpp..SH RELATED FUNCTION DOCUMENTATION.SH "QWMatrix operator* ( const QWMatrix & m1, const QWMatrix & m2 )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPReturns the product of \fIm1\fR * \fIm2\fR..PPNote that matrix multiplication is not commutative, i.e. a*b != b*a..SH "QDataStream & operator<< ( QDataStream & s, const QWMatrix & m )"Writes the matrix \fIm\fR to the stream \fIs\fR and returns a reference to the stream..PPSee also Format of the QDataStream operators..SH "QDataStream & operator>> ( QDataStream & s, QWMatrix & m )"Reads the matrix \fIm\fR from the stream \fIs\fR and returns a reference to the stream..PPSee also Format of the QDataStream operators..SH "SEE ALSO".BR http://doc.trolltech.com/qwmatrix.html.BR http://www.trolltech.com/faq/tech.html.SH COPYRIGHTCopyright 1992-2001 Trolltech AS, http://www.trolltech.com. See thelicense file included in the distribution for a complete licensestatement..SH AUTHORGenerated automatically from the source code..SH BUGSIf you find a bug in Qt, please report it as described in.BR http://doc.trolltech.com/bughowto.html .Good bug reports help us to help you. Thank you..PThe definitive Qt documentation is provided in HTML format; it islocated at $QTDIR/doc/html and can be read using Qt Assistant or witha web browser. This man page is provided as a convenience for thoseusers who prefer man pages, although this format is not officiallysupported by Trolltech. .PIf you find errors in this manual page, please report them to.BR qt-bugs@trolltech.com .Please include the name of the manual page (qwmatrix.3qt) and the Qtversion (3.0.0).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -