This utilities located in module ezdxf.algebra:

from ezdxf.algebra import Matrix44

Matrix44

class ezdxf.algebra.Matrix44

This is a pure Python implementation for 4x4 transformation matrices, to avoid dependency to big numerical packages like numpy, and before binary wheels, installation of these packages wasn’t always easy on Windows.

Matrix44 initialization:

  • Matrix44() is the identity matrix.
  • Matrix44(values) values is an iterable with the 16 components of the matrix.
  • Matrix44(row1, row2, row3, row4) four rows, each row with four values.
Matrix44.set(*args)

Reset matrix values:

  • set() creates the identity matrix.
  • set(values) values is an iterable with the 16 components of the matrix.
  • set(row1, row2, row3, row4) four rows, each row with four values.
Matrix44.__repr__()

Returns the representation string of the matrix:

Matrix44((col0, col1, col2, col3), (...), (...), (...))

Matrix44.get_row(row)

Get row as list of of four float values.

Matrix44.set_row(row, values)

Sets the values in a row.

Parameters:
  • row – row index [0..3]
  • values – four column values as iterable.
Matrix44.get_col(col)

Get column as list of of four float values.

Matrix44.set_col(col, values)

Sets the values in a column.

Parameters:
  • col – column index [0..3]
  • values – four column values as iterable.
Matrix44.copy()
Matrix44.__copy__()
Matrix44.scale(sx, sy=None, sz=None)

Class method returns a scaling transformation matrix. If sy is None, sy = sx, and if sz is None sz = sx.

Matrix44.translate(x, y, z)

Class method returns a translation matrix to (x, y, z).

Matrix44.x_rotate(angle)

Class method returns a rotation matrix about the x-axis.

Parameters:angle – rotation angle in radians
Matrix44.y_rotate(angle)

Class method returns a rotation matrix about the y-axis.

Parameters:angle – rotation angle in radians
Matrix44.z_rotate(angle)

Class method returns a rotation matrix about the z-axis.

param angle:rotation angle in radians
Matrix44.axis_rotate(axis, angle)

Class method returns a rotation matrix about an arbitrary axis.

Parameters:
  • axis – rotation axis as (x, y, z) tuple
  • angle – rotation angle in radians
Matrix44.xyz_rotate(angle_x, angle_y, angle_z)

Class method returns a rotation matrix for rotation about each axis.

Parameters:
  • angle_x – rotation angle about x-axis in radians
  • angle_y – rotation angle about y-axis in radians
  • angle_z – rotation angle about z-axis in radians
Matrix44.perspective_projection(left, right, top, bottom, near, far)

Class method returns a matrix for a 2d projection.

Parameters:
  • left – Coordinate of left of screen
  • right – Coordinate of right of screen
  • top – Coordinate of the top of the screen
  • bottom – Coordinate of the bottom of the screen
  • near – Coordinate of the near clipping plane
  • far – Coordinate of the far clipping plane
Matrix44.perspective_projection_fov(fov, aspect, near, far)

Class method returns a matrix for a 2d projection.

Parameters:
  • fov – The field of view (in radians)
  • aspect – The aspect ratio of the screen (width / height)
  • near – Coordinate of the near clipping plane
  • far – Coordinate of the far clipping plane
Matrix44.chain(*matrices)

Compose a transformation matrix from one or more matrices.

Matrix44.__setitem__(coord, value)

Set (row, column) element.

Matrix44.__getitem__(coord)

Get (row, column) element.

Matrix44.__iter__()

Iterates over all matrix values.

Matrix44.__mul__(other)

Returns a new matrix as result of the matrix multiplication with another matrix.

Matrix44.__imul__(other)

Inplace multiplication with another matrix.

Matrix44.fast_mul(other)

Multiplies this matrix with other matrix inplace.

Assumes that both matrices have a right column of (0, 0, 0, 1). This is True for matrices composed of rotations, translations and scales. fast_mul is approximately 25% quicker than __imul__().

Matrix44.rows()

Iterate over rows as 4-tuples.

Matrix44.columns()

Iterate over columns as 4-tuples.

Matrix44.transform(vector)

Transforms a 3d vector and return the result as a tuple.

Matrix44.transform_vectors(vectors)

Returns a list of transformed vectors.

Matrix44.transpose()

Swaps the rows for columns inplace.

Matrix44.get_transpose()

Returns a new transposed matrix.

Matrix44.determinant()

Returns determinant.

Matrix44.inverse()

Returns the inverse of the matrix.

Raises:ZeroDivisionError – if matrix has no inverse.