1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
|
'\" t
.TH QWMatrix 3qt "18 March 2002" "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 NAME
QWMatrix \- 2D transformations of a coordinate system
.SH SYNOPSIS
\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 DESCRIPTION
The QWMatrix class specifies 2D transformations of a coordinate system.
.PP
The 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.
.PP
This 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.
.PP
Example:
.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
.PP
A 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().
.PP
The 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
.PP
A 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
.PP
The 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.
.PP
The 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.
.PP
The identity matrix has \fIm11\fR and \fIm22\fR set to 1; all others are set to 0. This matrix maps a point to itself.
.PP
Translation 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.
.PP
Scaling 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%.
.PP
Shearing is controlled by \fIm12\fR and \fIm21\fR. Setting these elements to values different from zero will twist the coordinate system.
.PP
Rotation is achieved by carefully setting both the shearing factors and the scaling factors. The QWMatrix has a function that sets rotation directly.
.PP
QWMatrix 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
.PP
Here'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
.PP
QPainter 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.
.PP
See 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.
.PP
If the matrix is singular (not invertible), the identity matrix is returned.
.PP
If \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.
.PP
See also isInvertible().
.PP
Example: t14/cannon.cpp.
.SH "bool QWMatrix::isIdentity () const"
Returns TRUE if the matrix is the identity matrix; otherwise returns FALSE.
.PP
See also reset().
.SH "bool QWMatrix::isInvertible () const"
Returns TRUE if the matrix is invertible; otherwise returns FALSE.
.PP
See 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
.PP
Examples:
.)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.
.PP
Transforms ( \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.
.PP
Does 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.
.PP
Please use QWMatrix::mapRect() instead.
.PP
Note 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.
.PP
Does the same as operator *( const QPointArray &)
.SH "QRect QWMatrix::mapRect ( const QRect & rect ) const"
Returns the transformed rectangle \fIrect\fR.
.PP
The bounding rectangle is returned if rotation or shearing has been specified.
.PP
If you need to know the exact region \fIrect\fR maps to use operator*().
.PP
See 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.
.PP
Transforms the rectangle \fIr\fR.
.PP
Rotation and shearing a rectangle results in a more general region, which is returned here.
.PP
Calling 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.
.PP
See 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.
.PP
Transforms the region \fIr\fR.
.PP
Calling 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.
.PP
Returns 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.
.PP
All elements are set to zero, except \fIm11\fR and \fIm22\fR (scaling) that are set to 1.
.PP
See also isIdentity().
.SH "QWMatrix & QWMatrix::rotate ( double a )"
Rotates the coordinate system \fIa\fR degrees counterclockwise.
.PP
Returns a reference to the matrix.
.PP
See also translate(), scale() and shear().
.PP
Examples:
.)l canvas/canvas.cpp, 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.
.PP
Returns a reference to the matrix.
.PP
See also translate(), shear() and rotate().
.PP
Examples:
.)l canvas/canvas.cpp, 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.
.PP
Returns a reference to the matrix.
.PP
See also translate(), scale() and rotate().
.PP
Examples:
.)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.
.PP
Returns a reference to the matrix.
.PP
See also scale(), shear() and rotate().
.PP
Examples:
.)l canvas/canvas.cpp, 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.
.PP
Returns the product of \fIm1\fR * \fIm2\fR.
.PP
Note 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.
.PP
See 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.
.PP
See 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 COPYRIGHT
Copyright 1992-2001 Trolltech AS, http://www.trolltech.com. See the
license file included in the distribution for a complete license
statement.
.SH AUTHOR
Generated automatically from the source code.
.SH BUGS
If 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.
.P
The definitive Qt documentation is provided in HTML format; it is
located at $QTDIR/doc/html and can be read using Qt Assistant or with
a web browser. This man page is provided as a convenience for those
users who prefer man pages, although this format is not officially
supported by Trolltech.
.P
If 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 Qt
version (3.0.3).
|