QGIS API Documentation 4.1.0-Master (64029b4150b)
Loading...
Searching...
No Matches
qgsmatrix4x4.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsmatrix4x4.h
3 --------------------------------------
4 Date : July 2023
5 Copyright : (C) 2023 by Martin Dobias
6 Email : wonder dot sk at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGSMATRIX4X4_H
17#define QGSMATRIX4X4_H
18
19#include "qgis_core.h"
20#include "qgis_sip.h"
21#include "qgsvector3d.h"
22
23#include <QString>
24
25using namespace Qt::StringLiterals;
26
41class CORE_EXPORT QgsMatrix4x4
42{
43 public:
47 // clang-format off
49 double m11, double m12, double m13, double m14,
50 double m21, double m22, double m23, double m24,
51 double m31, double m32, double m33, double m34,
52 double m41, double m42, double m43, double m44
53 );
54 // clang-format on
55
56 bool operator==( const QgsMatrix4x4 &other ) const { return fuzzyEqual( other, 4 * std::numeric_limits<double>::epsilon() ); }
57
58 bool operator!=( const QgsMatrix4x4 &other ) const { return !( *this == other ); }
59
60
66 bool fuzzyEqual( const QgsMatrix4x4 &other, double epsilon = 1e-8 ) const
68
70 const double *constData() const SIP_SKIP { return *m; }
72 double *data() SIP_SKIP { return *m; }
73 // clang-format off
75 QList< double > dataList() const SIP_PYNAME( data ) SIP_HOLDGIL;
76 // clang-format on
77
81 void translate( const QgsVector3D &vector );
82
91 QgsVector3D map( const QgsVector3D &vector ) const SIP_HOLDGIL
92 {
93 return *this * vector;
94 }
95
107 QgsVector3D mapVector( const QgsVector3D &vector ) const SIP_HOLDGIL;
108
109
111 bool isIdentity() const SIP_HOLDGIL;
113 void setToIdentity() SIP_HOLDGIL;
114
120 void scale( const QgsVector3D &vector );
121
128 void rotate( double angle, double x, double y, double z );
129
136 void rotate( double angle, const QgsVector3D &vector );
137
143 double determinant() const;
144
145#ifdef SIP_RUN
146// clang-format off
147 SIP_PYOBJECT __repr__();
148 % MethodCode
149 QString str = u"<QgsMatrix4x4(%1, %2, %3, %4, %5, %6, %7, %8, %9, %10, %11, %12, %13, %14, %15, %16)>"_s
150 .arg( sipCpp->data()[0] )
151 .arg( sipCpp->data()[4] )
152 .arg( sipCpp->data()[8] )
153 .arg( sipCpp->data()[12] )
154 .arg( sipCpp->data()[1] )
155 .arg( sipCpp->data()[5] )
156 .arg( sipCpp->data()[9] )
157 .arg( sipCpp->data()[13] )
158 .arg( sipCpp->data()[2] )
159 .arg( sipCpp->data()[6] )
160 .arg( sipCpp->data()[10] )
161 .arg( sipCpp->data()[14] )
162 .arg( sipCpp->data()[3] )
163 .arg( sipCpp->data()[7] )
164 .arg( sipCpp->data()[11] )
165 .arg( sipCpp->data()[15] );
166 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
167 % End
168// clang-format on
169#endif
170
171#ifndef SIP_RUN
172 friend CORE_EXPORT QgsMatrix4x4 operator*( const QgsMatrix4x4 &m1, const QgsMatrix4x4 &m2 );
173 friend CORE_EXPORT QgsVector3D operator*( const QgsMatrix4x4 &matrix, const QgsVector3D &vector );
174#endif
175
176 private:
177 // Matrix data - in column-major order
178 double m[4][4];
179
181 explicit QgsMatrix4x4( int ) { } // cppcheck-suppress uninitMemberVarPrivate
182};
183
185CORE_EXPORT QgsVector3D operator*( const QgsMatrix4x4 &matrix, const QgsVector3D &vector );
187CORE_EXPORT QgsMatrix4x4 operator*( const QgsMatrix4x4 &m1, const QgsMatrix4x4 &m2 );
188
189
190#endif
A simple 4x4 matrix implementation useful for transformation in 3D space.
bool operator==(const QgsMatrix4x4 &other) const
QgsMatrix4x4()
Initializes identity matrix.
void setToIdentity()
Sets matrix to be identity matrix.
QgsVector3D map(const QgsVector3D &vector) const
Matrix-vector multiplication (vector is converted to homogeneous coordinates [X,Y,...
bool fuzzyEqual(const QgsMatrix4x4 &other, double epsilon=1e-8) const
Performs fuzzy comparison between this matrix and other using an epsilon.
bool operator!=(const QgsMatrix4x4 &other) const
double * data()
Returns pointer to the matrix data (stored in column-major order).
const double * constData() const
Returns pointer to the matrix data (stored in column-major order).
A 3D vector (similar to QVector3D) with the difference that it uses double precision instead of singl...
Definition qgsvector3d.h:33
#define SIP_SKIP
Definition qgis_sip.h:133
#define SIP_PYNAME(name)
Definition qgis_sip.h:88
#define SIP_HOLDGIL
Definition qgis_sip.h:178
QgsMargins operator*(const QgsMargins &margins, double factor)
Returns a QgsMargins object that is formed by multiplying each component of the given margins by fact...
Definition qgsmargins.h:245
CORE_EXPORT QgsVector3D operator*(const QgsMatrix4x4 &matrix, const QgsVector3D &vector)
Matrix-vector multiplication (vector is converted to homogeneous coordinates [X,Y,...