vray.Matrix

class vray.Matrix

Bases: object

A 3x3 column-major matrix. Each column is a vray.Vector that can be indexed. The usual mathematical operations are supported as well as equality checks. This object is immutable.

  • Matrix() -> new Matrix initialized to all zeroes

  • Matrix(diagonal) -> new Matrix initialized with ‘diagonal’ along the diagonal

  • Matrix(col0, col1, col2) -> new Matrix initialized with the 3 vray.Vector-s

Attributes

column0

Column0 of the matrix

column1

Column1 of the matrix

column2

Column2 of the matrix

identity

zero

Methods

__init__()

addDiagonal(self, diag)

Gets a copy of the matrix with added diagonal

addTransposed(self, matrix)

Gets a copy of the matrix with added another matrix transposed.

computeCholeskyDecomposition(self)

Compute the Cholesky decomposition of the given matrix: M = LL*.

computeQRFactorization(self)

Compute the QR-factorization m=q*r of a matrix m.

inverse(self)

Compute the inverse of a matrix.

makeRotationMatrixX(angle)

Creates a rotational matrix around the x axis given an angle in radians.

makeRotationMatrixY(angle)

Creates a rotational matrix around the y axis given an angle in radians.

makeRotationMatrixZ(angle)

Creates a rotational matrix around the z axis given an angle in radians.

orthogonal(self)

Get a orthogonal copy of the matrix(each column vector is orthogonal to the other two in 3D space).

orthonormal(self)

Get a orthonormal copy of the matrix

outerProduct(v1, v2)

Gets an outer product matrix of the two given vray.Vector-s.

replaceColumn(self, index, vector)

Get a copy of the matrix with changed column.

replaceRow(self, index, vector)

Get a copy of the matrix with changed row.

rotate(self, axis)

Get a copy of this matrix rotated around the given axis.

simpleCompose(rotation, scale, shear)

Composes a transformation matrix from primitive operations.

simpleDecompose(self)

Decomposes a non-singular transformation matrix into its primitive parts.

transpose(self)

Get a transposed copy of the matrix.

withoutScale(self)

Get the copy of the matrix with normalised columns.

addDiagonal(self, diag: Vector) → Matrix

Gets a copy of the matrix with added diagonal

  • diag - New vector value

addTransposed(self, matrix: Matrix) → Matrix

Gets a copy of the matrix with added another matrix transposed.

  • matrix - Another matrix to transpose and add

computeCholeskyDecomposition(self) → Matrix

Compute the Cholesky decomposition of the given matrix: M = LL*. The Cholesky decomposition is valid only for symmetric, positive-definite matrices. Throws a ValueError on failure. Returns the Matrix L on success

computeQRFactorization(self) → tuple[Matrix, Matrix]

Compute the QR-factorization m=q*r of a matrix m. The method fails to factorize singular and close to singular matrices. Throws a ValueError on failure. Returns a tuple (q, r) containing the result of the factorization on success.

  • q Orthogonal matrix factor, containing the rotational component of m.

  • r Upper triangular matrix factor, having the scales on the diagonal and the shears above it.

inverse(self) → Matrix

Compute the inverse of a matrix.

static makeRotationMatrixX(angle: float) → Matrix

Creates a rotational matrix around the x axis given an angle in radians.

static makeRotationMatrixY(angle: float) → Matrix

Creates a rotational matrix around the y axis given an angle in radians.

static makeRotationMatrixZ(angle: float) → Matrix

Creates a rotational matrix around the z axis given an angle in radians.

orthogonal(self) → Matrix

Get a orthogonal copy of the matrix(each column vector is orthogonal to the other two in 3D space).

orthonormal(self) → Matrix

Get a orthonormal copy of the matrix

static outerProduct(v1: Vector, v2: Vector) → Matrix

Gets an outer product matrix of the two given vray.Vector-s.

replaceColumn(self, index: int, vector: Vector) → Matrix

Get a copy of the matrix with changed column.

  • index - Column index to be changed.

  • vector - New vector value

replaceRow(self, index: int, vector: Vector) → Matrix

Get a copy of the matrix with changed row.

  • index - Row index to be changed.

  • vector - New vector value

rotate(self, axis: Vector) → Matrix

Get a copy of this matrix rotated around the given axis.

  • axis - An axis vector to rotate around. The length of the axis is the tangent of the angle of rotation.

static simpleCompose(rotation: Vector, scale: Vector, shear: Vector) → Matrix

Composes a transformation matrix from primitive operations.

  • rotation The X/Y/Z rotations in radians

  • scale Scale factors - could be negative

  • shear XY/XZ/YZ shear values

simpleDecompose(self) → tuple[Vector, Vector, Vector]

Decomposes a non-singular transformation matrix into its primitive parts. Returns a tuple (rotation, scale, shear) containing the primitive parts:

  • rotation The X/Y/Z rotations in radians

  • scale Scale factors - could be negative

  • shear XY/XZ/YZ shear values

transpose(self) → Matrix

Get a transposed copy of the matrix.

withoutScale(self) → Matrix

Get the copy of the matrix with normalised columns. This effectively removes scaling from a transform matrix.

column0

Column0 of the matrix

column1

Column1 of the matrix

column2

Column2 of the matrix

identity = Matrix(Vector(1, 0, 0), Vector(0, 1, 0), Vector(0, 0, 1))
zero = Matrix(Vector(0, 0, 0), Vector(0, 0, 0), Vector(0, 0, 0))