Class: QgsMatrix4x4

A simple 4x4 matrix implementation useful for transformation in 3D space.

It is similar to QMatrix4x4, but working with double precision values. Most of the time, doing transform using QMatrix4x4 is fine, however QgsMatrix4x4 is useful in situations where single precision floats are not enough. For example, when using transform matrix where translation component has values in order of millions.

Warning

Non-stable API, exposed to Python for unit testing only.

Added in version 3.34.

List of all members, including inherited members

Constructor

__init__

Methods

data

Returns matrix data (in column-major order)

determinant

Returns the determinant of this matrix.

fuzzyEqual

Performs fuzzy comparison between this matrix and other using an epsilon.

isIdentity

Returns whether this matrix is an identity matrix

map

Matrix-vector multiplication (vector is converted to homogeneous coordinates [X,Y,Z,1] and back)

mapVector

Maps vector by multiplying the top 3x3 portion of this matrix by vector.

rotate

Multiples this matrix by another that rotates coordinates through angle degrees about the vector (x, y, z).

scale

Multiplies this matrix by another that scales coordinates by the components of a vector.

setToIdentity

Sets matrix to be identity matrix

translate

Multiplies this matrix by another that translates coordinates by the components of a vector.

class qgis.core.QgsMatrix4x4[source]

Bases: object

__init__()

Initializes identity matrix

__init__(m11: float, m12: float, m13: float, m14: float, m21: float, m22: float, m23: float, m24: float, m31: float, m32: float, m33: float, m34: float, m41: float, m42: float, m43: float, m44: float)

Initializes matrix by setting all values in row-major order

Parameters:
  • m11 (float)

  • m12 (float)

  • m13 (float)

  • m14 (float)

  • m21 (float)

  • m22 (float)

  • m23 (float)

  • m24 (float)

  • m31 (float)

  • m32 (float)

  • m33 (float)

  • m34 (float)

  • m41 (float)

  • m42 (float)

  • m43 (float)

  • m44 (float)

__init__(a0: QgsMatrix4x4)
Parameters:

a0 (QgsMatrix4x4)

data(self) list[float]

Returns matrix data (in column-major order)

Return type:

list[float]

determinant(self) float[source]

Returns the determinant of this matrix.

Added in version 4.2.

Return type:

float

fuzzyEqual(self, other: QgsMatrix4x4, epsilon: float = 1e-08) bool[source]

Performs fuzzy comparison between this matrix and other using an epsilon.

Added in version 4.2.

Parameters:
Return type:

bool

isIdentity(self) bool[source]

Returns whether this matrix is an identity matrix

Return type:

bool

map(self, vector: QgsVector3D) QgsVector3D[source]

Matrix-vector multiplication (vector is converted to homogeneous coordinates [X,Y,Z,1] and back)

See also

mapVector()

Note

This function is not the same as mapVector(). For points, always use map(). mapVector() is suitable for vectors (directions) only.

Parameters:

vector (QgsVector3D)

Return type:

QgsVector3D

mapVector(self, vector: QgsVector3D) QgsVector3D[source]

Maps vector by multiplying the top 3x3 portion of this matrix by vector. The translation and projection components of this matrix are ignored. The matrix is applied pre-vector.

Parameters:

vector (QgsVector3D) – input vector to transform

See also

map()

Added in version 4.2.

Return type:

QgsVector3D

rotate(self, angle: float, x: float, y: float, z: float)[source]

Multiples this matrix by another that rotates coordinates through angle degrees about the vector (x, y, z).

Added in version 4.2.

rotate(self, angle: float, vector: QgsVector3D) Multiples this matrix by another that rotates coordinates through angle degrees about vector.

Added in version 4.2.

Parameters:
  • angle (float)

  • x (float)

  • y (float)

  • z (float)

scale(self, vector: QgsVector3D)[source]

Multiplies this matrix by another that scales coordinates by the components of a vector.

Added in version 4.2.

Parameters:

vector (QgsVector3D)

setToIdentity(self)[source]

Sets matrix to be identity matrix

translate(self, vector: QgsVector3D)[source]

Multiplies this matrix by another that translates coordinates by the components of a vector.

Parameters:

vector (QgsVector3D)