QWMatrix(3qt)

πŸ“¦ version 3.3.8b, in fedora 43, fedora 44

okay so bestie πŸ’– welcome to the QWMatrix(3qt) page β€” yes, section 3qt of the manual, she's a whole icon, and we are gonna get you fluent in 2D transformations of a coordinate system. Buckle up, this is part 1 of 2, so pace yourself 🫢


✨ NAME ✨

QWMatrix β€” literally 2D transformations of a coordinate system πŸ’…


🌸 SYNOPSIS 🌸

#include <qwmatrix.h>

πŸŽ€ Public Members πŸŽ€

  • QWMatrix ()
  • QWMatrix ( double m11, double m12, double m21, double m22, double dx, double dy )
  • void setMatrix ( double m11, double m12, double m21, double m22, double dx, double dy )
  • double m11 () const
  • double m12 () const
  • double m21 () const
  • double m22 () const
  • double dx () const
  • double dy () const
  • void map ( int x, int y, int * tx, int * ty ) const
  • void map ( double x, double y, double * tx, double * ty ) const
  • QRect mapRect ( const QRect & rect ) const
  • QPoint map ( const QPoint & p ) const
  • QRect map ( const QRect & r ) const (obsolete)
  • QPointArray map ( const QPointArray & a ) const
  • QRegion map ( const QRegion & r ) const
  • QRegion mapToRegion ( const QRect & rect ) const
  • QPointArray mapToPolygon ( const QRect & rect ) const
  • void reset ()
  • bool isIdentity () const
  • QWMatrix & translate ( double dx, double dy )
  • QWMatrix & scale ( double sx, double sy )
  • QWMatrix & shear ( double sh, double sv )
  • QWMatrix & rotate ( double a )
  • bool isInvertible () const
  • double det () const
  • QWMatrix invert ( bool * invertible = 0 ) const
  • bool operator== ( const QWMatrix & m ) const
  • bool operator!= ( const QWMatrix & m ) const
  • QWMatrix & operator*= ( const QWMatrix & m )
  • enum TransformationMode { Points, Areas }

πŸ¦‹ Static Public Members πŸ¦‹

  • void setTransformationMode ( QWMatrix::TransformationMode m )
  • TransformationMode transformationMode ()

  • QDataStream & operator<< ( QDataStream & s, const QWMatrix & m )
  • QDataStream & operator>> ( QDataStream & s, QWMatrix & m )

🌈 DESCRIPTION 🌈

The QWMatrix class specifies 2D transformations of a coordinate system. She's the blueprint, the vibe architect πŸ—οΈβœ¨

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. (Yes, downward. She's built different, it's giving math class but make it screens πŸ“‰)

This coordinate system is the 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.

Example, bestie, look at this beauty:

MyWidget::paintEvent( QPaintEvent * )
{
    QPainter p;                      // our painter
    QWMatrix m;                      // our transformation matrix
    m.rotate( 22.5 );                // rotated coordinate system
    p.begin( this );                 // start painting
    p.setWorldMatrix( m );           // use rotated coordinate system
    p.drawText( 30,20, "detator" );  // draw rotated text at 30,20
    p.end();                         // painting done
}

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().

The QWMatrix class contains a 3x3 matrix of the form:

m11
────
m21
dx

A matrix transforms a point in the plane to another point:

x' = m11*x + m21*y + dx
y' = m22*y + m12*x + dy

The point (x, y) is the original point, and (x', y') is the transformed point. (x', y') can be transformed back to (x, y) by performing the same operation on the inverted matrix. round trip, no cap πŸ”

The elements dx and dy specify horizontal and vertical translation. The elements m11 and m22 specify horizontal and vertical scaling. The elements m12 and m21 specify horizontal and vertical shearing.

The identity matrix has m11 and m22 set to 1; all others are set to 0. This matrix maps a point to itself. it's the "do nothing, serve no cunt, stay exactly as you are" queen πŸ‘‘

Translation is the simplest transformation. Setting dx and dy will move the coordinate system dx units along the X axis and dy units along the Y axis.

Scaling can be done by setting m11 and m22. For example, setting m11 to 2 and m22 to 1.5 will double the height and increase the width by 50%.

Shearing is controlled by m12 and m21. Setting these elements to values different from zero will twist the coordinate system. twisted, but like, mathematically πŸŒ€

Rotation is achieved by carefully setting both the shearing factors and the scaling factors. The QWMatrix also has a function that sets rotation directly.

QWMatrix lets you combine transformations like this:

QWMatrix m;           // identity matrix
m.translate(10, -20); // first translate (10,-20)
m.rotate(25);         // then rotate 25 degrees
m.scale(1.2, 0.7);    // finally scale it

Here's the same example using basic matrix operations:

double a    = pi/180 * 25;         // convert 25 to radians
double sina = sin(a);
double cosa = cos(a);
QWMatrix m1(1, 0, 0, 1, 10, -20);  // translation matrix
QWMatrix m2( cosa, sina,           // rotation matrix
            -sina, cosa, 0, 0 );
QWMatrix m3(1.2, 0, 0, 0.7, 0, 0); // scaling matrix
QWMatrix m;
m = m3 * m2 * m1;                  // combine all transformations

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. efficiency era, we love to see it πŸ’…

See also QPainter::setWorldMatrix(), QPixmap::xForm(), Graphics Classes, and Image Processing Classes.


🧚 Member Type Documentation 🧚

QWMatrix::TransformationMode

QWMatrix offers two transformation modes. Calculations can either be done in terms of points (Points mode, the default), or in terms of area (Area mode).

In Points mode the transformation is applied to the points that mark out the shape's bounding line. In Areas mode the transformation is applied in such a way that the area of the contained region is correctly transformed under the matrix.

  • QWMatrix::Points β€” transformations are applied to the shape's points.
  • QWMatrix::Areas β€” transformations are applied (e.g. to the width and height) so that the area is transformed.

Example, okay so imagine this:

Suppose we have a rectangle, QRect( 10, 20, 30, 40 ) and a transformation matrix QWMatrix( 2, 0, 0, 2, 0, 0 ) to double the rectangle's size.

In Points mode, the matrix will transform the top-left (10,20) and the bottom-right (39,59) points producing a rectangle with its top-left point at (20,40) and its bottom-right point at (78,118), i.e. with a width of 59 and a height of 79.

In Areas mode, the matrix will transform the top-left point in the same way as in Points mode to (20/40), and double the width and height, so the bottom-right will become (69,99), i.e. a width of 60 and a height of 80.

Because integer arithmetic is used (for speed), rounding differences mean that the modes will produce slightly different results given the same shape and the same transformation, especially when scaling up. This also means that some operations are not commutative. ⚠️

Under Points mode, matrix * ( region1 | region2 ) is not equal to matrix * region1 | matrix * region2. Under Area mode, matrix * (pointarray[i]) is not neccesarily equal to (matrix * pointarry)[i].

[Image Omitted] πŸ–ΌοΈ (she was there, we just can't show you, sad)


πŸ’… MEMBER FUNCTION DOCUMENTATION πŸ’…

QWMatrix::QWMatrix ()

Constructs an identity matrix. All elements are set to zero except m11 and m22 (scaling), which are set to 1. fresh start, clean slate, no baggage πŸ’–

QWMatrix::QWMatrix ( double m11, double m12, double m21, double m22, double dx, double dy )

Constructs a matrix with the elements, m11, m12, m21, m22, dx and dy.

double QWMatrix::det () const

Returns the matrix's determinant. the math girlies know πŸ”₯

double QWMatrix::dx () const

Returns the horizontal translation.

double QWMatrix::dy () const

Returns the vertical translation.

QWMatrix QWMatrix::invert ( bool * invertible = 0 ) const

Returns the inverted matrix.

If the matrix is singular (not invertible), the identity matrix is returned. 🫠

If invertible is not 0: the value of *invertible is set to TRUE if the matrix is invertible; otherwise *invertible is set to FALSE.

See also isInvertible().

Example: t14/cannon.cpp.

bool QWMatrix::isIdentity () const

Returns TRUE if the matrix is the identity matrix; otherwise returns FALSE.

See also reset().

bool QWMatrix::isInvertible () const

Returns TRUE if the matrix is invertible; otherwise returns FALSE.

See also invert().

double QWMatrix::m11 () const

Returns the X scaling factor.

double QWMatrix::m12 () const

Returns the vertical shearing factor.

double QWMatrix::m21 () const

Returns the horizontal shearing factor.

double QWMatrix::m22 () const

Returns the Y scaling factor.

void QWMatrix::map ( int x, int y, int * tx, int * ty ) const

Transforms ( x, y ) to ( *tx, *ty ) using the formulae:

*tx = m11*x + m21*y + dx  (rounded to the nearest integer)
*ty = m22*y + m12*x + dy  (rounded to the nearest integer)

Examples:

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.

Transforms ( x, y ) to ( *tx, *ty ) using the following formulae:

*tx = m11*x + m21*y + dx
*ty = m22*y + m12*x + dy

QPoint QWMatrix::map ( const QPoint & p ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Transforms p to using the formulae:

retx = m11*px + m21*py + dx  (rounded to the nearest integer)
rety = m22*py + m12*px + dy  (rounded to the nearest integer)

QRect QWMatrix::map ( const QRect & r ) const

⚠️ This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.

Please use QWMatrix::mapRect() instead. okay bestie, retire her, she served her time πŸ’€

Note that this method does return the bounding rectangle of the r, when shearing or rotations are used.

QPointArray QWMatrix::map ( const QPointArray & a ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns the point array a transformed by calling map for each point.

QRegion QWMatrix::map ( const QRegion & r ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Transforms the region r.

Calling this method can be rather expensive, if rotations or shearing are used. πŸ’Έ careful with your coins, girl

QRect QWMatrix::mapRect ( const QRect & rect ) const

Returns the transformed rectangle rect.

The bounding rectangle is returned if rotation or shearing has been specified.

If you need to know the exact region rect maps to use operator*().

See also operator*().

Example: xform/xform.cpp.

QPointArray QWMatrix::mapToPolygon ( const QRect & rect ) const

polygon o'clock bestie ✨ this hands you back the transformed rectangle rect, but as a polygon.

Now here's the tea πŸ«– β€” polygons and rectangles do not behave identically when they get transformed, because of integer rounding. So matrix.map( QPointArray( rect ) ) is not always gonna be the same thing as matrix.mapToPolygon( rect ). Fr fr, they can genuinely differ. πŸ™ˆ


QRegion QWMatrix::mapToRegion ( const QRect & rect ) const

Returns the transformed rectangle rect. πŸ’«

But listen β€” if that rectangle got rotated or sheared, you might get back a region that is not rectangular. It's giving chaos geometry. 😭

Calling this method can be expensive, bestie, if rotations or shearing are used. πŸ’Έ

If all you actually need is the bounding rectangle of the region you got back, use mapRect() instead β€” it's a lot faster than this function. πŸƒβ™€οΈπŸ’¨

See also: QWMatrix::mapRect().


bool QWMatrix::operator!= ( const QWMatrix & m ) const

Returns TRUE if this matrix is not equal to m; otherwise returns FALSE. πŸ’…


QWMatrix & QWMatrix::operator*= ( const QWMatrix & m )

Returns the result of multiplying this matrix by matrix m. βœ–οΈ math girlie moment.


bool QWMatrix::operator== ( const QWMatrix & m ) const

Returns TRUE if this matrix is equal to m; otherwise returns FALSE. 🫢


void QWMatrix::reset ()

Resets the matrix to an identity matrix. πŸŽ€

Every single element gets set to zero, except m11 and m22 (the scaling ones) which get set to 1.

See also: isIdentity().


QWMatrix & QWMatrix::rotate ( double a )

Rotates the coordinate system a degrees counterclockwise. πŸ”„βœ¨

Returns a reference to the matrix.

See also: translate(), scale(), and shear().

Examples:


QWMatrix & QWMatrix::scale ( double sx, double sy )

Scales the coordinate system unit by sx horizontally and sy vertically. πŸ“

Returns a reference to the matrix.

See also: translate(), shear(), and rotate().

Examples:


void QWMatrix::setMatrix ( double m11, double m12, double m21, double m22, double dx, double dy )

Sets the matrix elements to the specified values: m11, m12, m21, m22, dx and dy. πŸ› οΈ No cap, that's the whole thing.


void QWMatrix::setTransformationMode ( QWMatrix::TransformationMode m )

[static]

Sets the transformation mode that QWMatrix and painter transformations use to m. πŸ‘‘

See also: QWMatrix::TransformationMode.


QWMatrix & QWMatrix::shear ( double sh, double sv )

Shears the coordinate system by sh horizontally and sv vertically. πŸ¦‹ (yes it's giving italic fonts, that's literally the vibe)

Returns a reference to the matrix.

See also: translate(), scale(), and rotate().

Examples:


TransformationMode QWMatrix::transformationMode () [static]

Returns the current transformation mode. πŸ”

See also: QWMatrix::TransformationMode.


QWMatrix & QWMatrix::translate ( double dx, double dy )

Moves the coordinate system dx along the X-axis and dy along the Y-axis. πŸšΆβ™€οΈβž‘οΈ

Returns a reference to the matrix.

See also: scale(), shear(), and rotate().

Examples:


QDataStream & operator<< ( QDataStream & s, const QWMatrix & m )

Writes the matrix m to the stream s and returns a reference to the stream. πŸ“€πŸ’–

See also: Format of the QDataStream operators.


QDataStream & operator>> ( QDataStream & s, QWMatrix & m )

Reads the matrix m from the stream s and returns a reference to the stream. πŸ“₯🫢

See also: Format of the QDataStream operators.


🌈 SEE ALSO 🌈


Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the license file included in the distribution for a complete license statement. πŸ“œ


πŸŽ€ AUTHOR πŸŽ€

Generated automatically from the source code. πŸ€– (the robots wrote this one, not me)


πŸ’€ BUGS πŸ’€

If you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. Good bug reports help us to help you. Thank you. πŸ™

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. 😭

If you find errors in this manual page, please report them to qt-bugs@trolltech.com. Please include the name of the manual page (qwmatrix.3qt) and the Qt version (3.3.8). πŸ›βœ¨


okay that's the whole page bestie, you ate that πŸ’…

This icon of a man page came from Trolltech AS, dated 2 February 2007, and it's the QWMatrix(3qt) page β€” shoutout to the source and the date, couldn't have done it without them 🫢🌸

πŸ“¦ where this page comes from