File: qwmatrix.html

package info (click to toggle)
qt-embedded 2.3.2-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 68,608 kB
  • ctags: 45,998
  • sloc: cpp: 276,654; ansic: 71,987; makefile: 29,074; sh: 12,305; yacc: 2,465; python: 1,863; perl: 481; lex: 480; xml: 68; lisp: 15
file content (262 lines) | stat: -rw-r--r-- 16,623 bytes parent folder | download
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Qt Toolkit - QWMatrix Class</title><style type="text/css"><!--
h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }body { background: white; color: black; }
--></style>
</head><body bgcolor="#ffffff">

<table width="100%">
<tr><td><a href="index.html">
<img width="100" height="100" src="qtlogo.png"
alt="Home" border="0"><img width="100"
height="100" src="face.png" alt="Home" border="0">
</a><td valign=top><div align=right><img src="dochead.png" width="472" height="27"><br>
<a href="classes.html"><b>Classes</b></a>
-<a href="annotated.html">Annotated</a>
- <a href="hierarchy.html">Tree</a>
-<a href="functions.html">Functions</a>
-<a href="index.html">Home</a>
-<a href="topicals.html"><b>Structure</b></a>
</div>
</table>

<h1 align=center>QWMatrix Class Reference</h1><br clear="all">
<p>
The QWMatrix class specifies 2D transformations of a coordinate system.
<a href="#details">More...</a>
<p>
<code>#include &lt;<a href="qwmatrix-h.html">qwmatrix.h</a>&gt;</code>
<p><a href="qwmatrix-members.html">List of all member functions.</a>
<h2>Public Members</h2>
<ul>
<li><div class="fn"><a href="#5b24cf"><b>QWMatrix</b></a>()</div>
<li><div class="fn"><a href="#1ee86a"><b>QWMatrix</b></a>(doublem11, doublem12, doublem21, doublem22, doubledx, doubledy)</div>
<li><div class="fn">void<a href="#758626"><b>setMatrix</b></a>(doublem11, doublem12, doublem21, doublem22, doubledx, doubledy)</div>
<li><div class="fn">double<a href="#b24a8d"><b>m11</b></a>()const</div>
<li><div class="fn">double<a href="#f60706"><b>m12</b></a>()const</div>
<li><div class="fn">double<a href="#3da1aa"><b>m21</b></a>()const</div>
<li><div class="fn">double<a href="#5ceba1"><b>m22</b></a>()const</div>
<li><div class="fn">double<a href="#58f7fe"><b>dx</b></a>()const</div>
<li><div class="fn">double<a href="#600479"><b>dy</b></a>()const</div>
<li><div class="fn">void<a href="#c5581f"><b>map</b></a>(intx, inty, int*tx, int*ty)const</div>
<li><div class="fn">void<a href="#83c725"><b>map</b></a>(doublex, doubley, double*tx, double*ty)const</div>
<li><div class="fn">QPoint<a href="#fe18db"><b>map</b></a>(constQPoint&amp;)const</div>
<li><div class="fn">QRect<a href="#a5969f"><b>map</b></a>(constQRect&amp;)const</div>
<li><div class="fn">QPointArray<a href="#95bc92"><b>map</b></a>(constQPointArray&amp;)const</div>
<li><div class="fn">void<a href="#e13f59"><b>reset</b></a>()</div>
<li><div class="fn">QWMatrix&amp;<a href="#e4b716"><b>translate</b></a>(doubledx, doubledy)</div>
<li><div class="fn">QWMatrix&amp;<a href="#41a356"><b>scale</b></a>(doublesx, doublesy)</div>
<li><div class="fn">QWMatrix&amp;<a href="#b99fbb"><b>shear</b></a>(doublesh, doublesv)</div>
<li><div class="fn">QWMatrix&amp;<a href="#71020d"><b>rotate</b></a>(doublea)</div>
<li><div class="fn">QWMatrix<a href="#4b7815"><b>invert</b></a>(bool*=0)const</div>
<li><div class="fn">bool<a href="#1a89f8"><b>operator==</b></a>(constQWMatrix&amp;)const</div>
<li><div class="fn">bool<a href="#4d0879"><b>operator!=</b></a>(constQWMatrix&amp;)const</div>
<li><div class="fn">QWMatrix&amp;<a href="#9915db"><b>operator*=</b></a>(constQWMatrix&amp;)</div>
</ul>
<h2>Related Functions</h2>
(Note that these are not member functions.)
<ul>
<li>QDataStream &amp; <a href="qwmatrix.html#52be3f"><b>operator&gt;&gt;</b></a> (QDataStream &amp; s, QWMatrix &amp; m)
<li>QDataStream &amp; <a href="qwmatrix.html#d68356"><b>operator&lt;&lt;</b></a> (QDataStream &amp; s, const QWMatrix &amp; m)
<li>QWMatrix <a href="qwmatrix.html#e3021d"><b>operator*</b></a> (const QWMatrix &amp; m1, const QWMatrix &amp; m2)
</ul>
<hr><h2><a name="details"></a>Detailed Description</h2>
The QWMatrix class specifies 2D transformations of a coordinate system.
<p>
The standard coordinate system of a <a href="qpaintdevice.html">paint
device</a> has the origin located at the top left position. X
values increase to the right, and Y values increase downwards.
<p>This coordinate system is default for the <a href="qpainter.html">QPainter</a>, which renders
graphics in a paint device. A user-defined coordinate system can be
specified by setting a QWMatrix for the painter.
<p>Example:
<pre>    MyWidget::paintEvent( <a href="qpaintevent.html">QPaintEvent</a> * )
    {
      <a href="qpainter.html">QPainter</a> p;                       // our painter
      <a href="qwmatrix.html">QWMatrix</a> m;                       // our transformation matrix
      m.<a href="#71020d">rotate</a>( 22.5 );                 // rotated coordinate system
      p.<a href="qpainter.html#02ed5d">begin</a>( this );                  // start painting
      p.<a href="qpainter.html#862c4d">setWorldMatrix</a>( m );            // use rotated coordinate system
      p.<a href="qpainter.html#0f088f">drawText</a>( 30,20, "detator" );   // draw rotated text at 30,20
      p.<a href="qpainter.html#365784">end</a>();                          // painting done
    }
</pre>
<p>A matrix specifies how to translate, scale, shear or rotate the
graphics, and the actual transformation is performed by the drawing
routines in QPainter and by <a href="qpixmap.html#ff5fcf">QPixmap::xForm</a>().
<p>The QWMatrix class contains a 3*3 matrix of the form:
<pre>
    m11  m12  0
    m21  m22  0
    dx   dy   1
  </pre>
<p>A matrix transforms a point in the plane to another point:
<pre>    x' = m11*x + m21*y + dx
    y' = m22*y + m12*x + dy
</pre>
<p>The point <em>(x,y)</em> is the original point, and <em>(x',y')</em> is the
transformed point.  <em>(x',y')</em> can be transformed back to <em>(x,y)</em>
by performing the same operation on the <a href="#4b7815">inverted matrix</a>.
<p>The elements <em>dx</em> and <em>dy</em> specify horisontal and vertical
translation.  The elements <em>m11</em> and <em>m22</em> specify horisontal and
vertical scaling.  The elements <em>m12</em> and <em>m21</em> specify horisontal
and vertical shearing.
<p>The identity matrix has <em>m11</em> and <em>m22</em> set to 1, all others set
to 0.  This matrix maps a point to itself.
<p>Translation is the simplest transformation. Setting <em>dx</em> and <em>dy</em>
will move the coordinate system <em>dx</em> units along the X axis and <em>dy</em> units along the Y axis.
<p>Scaling can be done by setting <em>m11</em> and <em>m22.</em>  For example,
setting <em>m11</em> to 2 and <em>m22</em> to 1.5 will double the height and
increase the width by 50%.
<p>Shearing is controlled by <em>m12</em> and <em>m21.</em> Setting these elements
to values different from zero will twist the coordinate system.
<p>Rotation is achieved by carefully setting both the shearing factors
and the scaling factors.  The QWMatrix has a function that sets
<a href="#71020d">rotation</a> directly.
<p>QWMatrix lets you combine transformations like this:
<pre>    <a href="qwmatrix.html">QWMatrix</a> m;                                 // identity matrix
    m.<a href="#e4b716">translate</a>(10, -20);                       // first translate (10,-20)
    m.<a href="#71020d">rotate</a>(25);                               // then rotate 25 degrees
    m.<a href="#41a356">scale</a>(1.2, 0.7);                          // finally scale it
</pre>
<p>The same example, but using basic matrix operations:
<pre>    double a    = pi/180 * 25;                  // convert 25 to radians
    double sina = sin(a);
    double cosa = cos(a);
    <a href="qwmatrix.html">QWMatrix</a> m1(0, 0, 0, 0, 10, -20);           // translation matrix
    <a href="qwmatrix.html">QWMatrix</a> m2( cosa, sina,                    // rotation matrix
                -sina, cosa, 0, 0 );
    <a href="qwmatrix.html">QWMatrix</a> m3(1.2, 0, 0, 0.7, 0, 0);          // scaling matrix
    <a href="qwmatrix.html">QWMatrix</a> m;
    m = m3 * m2 * m1;                           // combine all transformations
</pre>
<p><a href="qpainter.html">QPainter</a> has functions that <a href="qpainter.html#eb778c">translate</a>, <a href="qpainter.html#e5ec3e">scale</a>, <a href="qpainter.html#c8634b">shear</a> and <a href="qpainter.html#b5205c">rotate</a> the coordinate system without using a
QWMatrix.  These functions are very convenient, however, if you want to
perform more than a single transform operation, it is more efficient to
build a QWMatrix and call <a href="qpainter.html#862c4d">QPainter::setWorldMatrix</a>().
<p>See also  <a href="qpainter.html#862c4d">QPainter::setWorldMatrix</a>() and <a href="qpixmap.html#ff5fcf">QPixmap::xForm</a>().
<p>Examples:
 <a href="qtimage-qtimage-cpp.html#QWMatrix">qtimage/qtimage.cpp</a>
 <a href="xform-xform-cpp.html#QWMatrix">xform/xform.cpp</a>
 <a href="drawdemo-drawdemo-cpp.html#QWMatrix">drawdemo/drawdemo.cpp</a>
 <a href="qmag-qmag-cpp.html#QWMatrix">qmag/qmag.cpp</a>
 <a href="desktop-desktop-cpp.html#QWMatrix">desktop/desktop.cpp</a>
 <a href="movies-main-cpp.html#QWMatrix">movies/main.cpp</a>

<hr><h2>Member Function Documentation</h2>
<h3 class="fn"><a name="5b24cf"></a>QWMatrix::QWMatrix()</h3>
<p>Constructs an identity matrix.  All elements are set to zero,
except <em>m11</em> and <em>m22</em> (scaling) which are set to 1.
<h3 class="fn"><a name="1ee86a"></a>QWMatrix::QWMatrix(doublem11, doublem12, doublem21, doublem22, doubledx, doubledy)</h3>
<p>Constructs a matrix with the specified elements.
<h3 class="fn">double<a name="58f7fe"></a>QWMatrix::dx()const</h3>
<p>Returns the horizontal translation.
<h3 class="fn">double<a name="600479"></a>QWMatrix::dy()const</h3>
<p>Returns the vertical translation.
<h3 class="fn">QWMatrix<a name="4b7815"></a>QWMatrix::invert(bool*invertible=0)const</h3>
<p>Returns the inverted matrix.
<p>If the matrix is singular (not invertible), then the identity matrix is
returned.
<p>If <em>*invertible</em> is not null, then the value of <em>*invertible</em> will
be set to TRUE or FALSE to tell if the matrix is invertible or not.
<h3 class="fn">double<a name="b24a8d"></a>QWMatrix::m11()const</h3>
<p>Returns the X scaling factor.
<h3 class="fn">double<a name="f60706"></a>QWMatrix::m12()const</h3>
<p>Returns the vertical shearing factor.
<h3 class="fn">double<a name="3da1aa"></a>QWMatrix::m21()const</h3>
<p>Returns the horizontal shearing factor.
<h3 class="fn">double<a name="5ceba1"></a>QWMatrix::m22()const</h3>
<p>Returns the Y scaling factor.
<h3 class="fn"><a href="qpoint.html">QPoint</a><a name="fe18db"></a>QWMatrix::map(const<a href="qpoint.html">QPoint</a>&amp;p)const</h3>
<p>Returns the transformed <em>p.</em>
<h3 class="fn"><a href="qpointarray.html">QPointArray</a><a name="95bc92"></a>QWMatrix::map(const<a href="qpointarray.html">QPointArray</a>&amp;a)const</h3>
<p>Returns the point array <em>a</em> transformed by calling map for each point.
<h3 class="fn"><a href="qrect.html">QRect</a><a name="a5969f"></a>QWMatrix::map(const<a href="qrect.html">QRect</a>&amp;r)const</h3>
<p>Returns the transformed rectangle <em>r.</em>
<p>If rotation or shearing has been specified, then the bounding rectangle
will be returned.
<h3 class="fn">void<a name="83c725"></a>QWMatrix::map(doublex, doubley, double*tx, double*ty)const</h3>
<p>Transforms <em>(x,y)</em> to <em>(*tx,*ty),</em> using the formulae:
<p><pre>    *tx = m11*x + m21*y + dx
    *ty = m22*y + m12*x + dy
</pre>
<p>Examples:
 <a href="xform-xform-cpp.html#map">xform/xform.cpp</a>
<h3 class="fn">void<a name="c5581f"></a>QWMatrix::map(intx, inty, int*tx, int*ty)const</h3>
<p>Transforms <em>(x,y)</em> to <em>(*tx,*ty),</em> using the formulae:
<p><pre>    *tx = m11*x + m21*y + dx  --  (rounded to the nearest integer)
    *ty = m22*y + m12*x + dy  --  (rounded to the nearest integer)
</pre>
<h3 class="fn">bool<a name="4d0879"></a>QWMatrix::operator!=(constQWMatrix&amp;m)const</h3>
<p>Returns TRUE if this matrix is not equal to <em>m.</em>
<h3 class="fn">QWMatrix&amp;<a name="9915db"></a>QWMatrix::operator*=(constQWMatrix&amp;m)</h3>
<p>Returns the result of multiplying this matrix with <em>m.</em>
<h3 class="fn">bool<a name="1a89f8"></a>QWMatrix::operator==(constQWMatrix&amp;m)const</h3>
<p>Returns TRUE if this matrix is equal to <em>m.</em>
<h3 class="fn">void<a name="e13f59"></a>QWMatrix::reset()</h3>
<p>Resets the matrix to an identity matrix.
<p>All elements are set to zero, except <em>m11</em> and <em>m22</em> (scaling)
that are set to 1.
<h3 class="fn">QWMatrix&amp;<a name="71020d"></a>QWMatrix::rotate(doublea)</h3>
<p>Rotates the coordinate system <em>a</em> degrees counterclockwise.
<p>Returns a reference to the matrix.
<p>See also  <a href="#e4b716">translate</a>(), <a href="#41a356">scale</a>() and <a href="#b99fbb">shear</a>().
<p>Examples:
 <a href="xform-xform-cpp.html#rotate">xform/xform.cpp</a>
 <a href="drawdemo-drawdemo-cpp.html#rotate">drawdemo/drawdemo.cpp</a>
 <a href="desktop-desktop-cpp.html#rotate">desktop/desktop.cpp</a>
<h3 class="fn">QWMatrix&amp;<a name="41a356"></a>QWMatrix::scale(doublesx, doublesy)</h3>
<p>Scales the coordinate system unit by <em>sx</em> horizontally and <em>sy</em>
vertically.
<p>Returns a reference to the matrix.
<p>See also  <a href="#e4b716">translate</a>(), <a href="#b99fbb">shear</a>() and <a href="#71020d">rotate</a>().
<p>Examples:
 <a href="qtimage-qtimage-cpp.html#scale">qtimage/qtimage.cpp</a>
 <a href="xform-xform-cpp.html#scale">xform/xform.cpp</a>
 <a href="movies-main-cpp.html#scale">movies/main.cpp</a>
<h3 class="fn">void<a name="758626"></a>QWMatrix::setMatrix(doublem11, doublem12, doublem21, doublem22, doubledx, doubledy)</h3>
<p>Sets the matrix elements to the specified values.
<h3 class="fn">QWMatrix&amp;<a name="b99fbb"></a>QWMatrix::shear(doublesh, doublesv)</h3>
<p>Shears the coordinate system  by <em>sh</em> horizontally and <em>sv</em> vertically.
<p>Returns a reference to the matrix.
<p>See also  <a href="#e4b716">translate</a>(), <a href="#41a356">scale</a>() and <a href="#71020d">rotate</a>().
<p>Examples:
 <a href="xform-xform-cpp.html#shear">xform/xform.cpp</a>
 <a href="drawdemo-drawdemo-cpp.html#shear">drawdemo/drawdemo.cpp</a>
<h3 class="fn">QWMatrix&amp;<a name="e4b716"></a>QWMatrix::translate(doubledx, doubledy)</h3>
<p>Moves the coordinate system <em>dx</em> along the X-axis and <em>dy</em>
along the Y-axis.
<p>Returns a reference to the matrix.
<p>See also  <a href="#41a356">scale</a>(), <a href="#b99fbb">shear</a>() and <a href="#71020d">rotate</a>().
<p>Examples:
 <a href="xform-xform-cpp.html#translate">xform/xform.cpp</a>
 <a href="drawdemo-drawdemo-cpp.html#translate">drawdemo/drawdemo.cpp</a>
<hr><h2>Related Functions</h2>
<h3><a href="qdatastream.html">QDataStream</a> &amp; <a name="52be3f"></a>operator&gt;&gt; (<a href="qdatastream.html">QDataStream</a> &amp; s, QWMatrix &amp; m)</h3>
<p>Reads a matrix from the stream and returns a reference to the stream.
<p>See also  <a href="datastreamformat.html">Format of the QDataStream operators</a>

<h3><a href="qdatastream.html">QDataStream</a> &amp; <a name="d68356"></a>operator&lt;&lt; (<a href="qdatastream.html">QDataStream</a> &amp; s, const QWMatrix &amp; m)</h3>
<p>Writes a matrix to the stream and returns a reference to the stream.
<p>See also  <a href="datastreamformat.html">Format of the QDataStream operators</a>

<h3>QWMatrix <a name="e3021d"></a>operator* (const QWMatrix &amp; m1, const QWMatrix &amp; m2)</h3>
<p>Returns the product <em>m1</em> * <em>m2.</em>
<p>Remember that matrix multiplication is not commutative, thus
a*b != b*a.

<hr><p>
Search the documentation, FAQ, qt-interest archive and more (uses
<a href="http://www.trolltech.com">www.trolltech.com</a>):<br>
<form method=post action="http://www.trolltech.com/search.cgi">
<input type=hidden name="version" value="2.3.2"><nobr>
<input size="50" name="search"><input type=submit value="Search">
</nobr></form><hr><p>
This file is part of the <a href="index.html">Qt toolkit</a>,
copyright &copy; 1995-2001
<a href="http://www.trolltech.com">Trolltech</a>, all rights reserved.<p><address><hr><div align="center">
<table width="100%" cellspacing="0" border="0"><tr>
<td>Copyright  2001 Trolltech<td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a>
<td align="right"><div align="right">Qt version 2.3.2</div>
</table></div></address></body></html>