Methods
__init__(values)
Return a new Matrix2. You can pass no parameters (the result will contain all zeros), a float (the result’s diagonal values will contain that float and the rest is all zeros), a sequence of 4 floats, or a sequence of sequences of 2 floats.
>>> hou.Matrix2() <hou.Matrix2 [[0, 0], [0, 0]]]> >>> hou.Matrix2(1) <hou.Matrix2 [[1, 0], [0, 1]]> >>> hou.Matrix2((0, 1, 2, 3)) <hou.Matrix2 [[0, 1], [2, 3]]> >>> hou.Matrix2(((0, 1), (3, 4))) <hou.Matrix2 [[0, 1], [2, 3]]>
Note that Houdini’s matrices are stored in row-major order, so the matrix’s contents are grouped by row.
isAlmostEqual(matrix2, tolerance=0.00001)
→ bool
Returns whether this matrix is equal to another, within a tolerance.
at(row, col)
→ double
Return the value of the matrix at the given row and column.
Raises IndexError if the row or column are not between 0 and 1, inclusive. Note that negative indices will not index from the end.
setAt(row, col, value)
Set the value of the matrix at the given row and column.
Raises IndexError if the row or column are not between 0 and 1, inclusive. Note that negative indices will not index from the end.
asTuple()
→ tuple
of float
Return the contents of the matrix as a tuple of 4 floats.
asTupleOfTuples()
→ tuple
of tuple
of float
Return the contents of the matrix as a tuple of tuples of 2 floats.
setTo(tuple)
Set this matrix’s contents. The sequence may contain either 4 floats or 2 sequences, each with 2 floats.
See hou.Matrix2.__init__() for examples of suitable parameter values.
setToIdentity()
Set this matrix to the multiplicative identity, having 1's in the diagonal.
The matrix will contain the values
[[1, 0], [0, 1]]
. Note that you can construct a new
matrix with these values using hou.Matrix2(1)
.
setToZero()
Set this matrix to contain all zeros.
Note that you can construct a new matrix with all zeros with
hou.Matrix2()
.
__add__(matrix2)
→ hou.Matrix2
Add two matrices by adding corresponding entries together and return a new
matrix. This method lets you write m1 + m2
, where m1
and m2
are
Matrix2 objects.
__sub__(matrix2)
→ hou.Matrix2
Subtract another matrix from this one, subtracting corresponding entries,
and return a new matrix. This method lets you write m1 - m2
, where m1
and m2
are Matrix2 objects.
__mul__(matrix2_or_scalar)
→ hou.Matrix2
Multiply this matrix by another matrix or by a scalar, returning a new
matrix. This method lets you write m1 * m2
, where m1
and m2
are
Matrix2 objects, or m1 * s
, where s
is a float.
See Wikipedia’s matrix multiplication page for details on how each element in the result is computed.
preMult(matrix2)
→ hou.Matrix2
Returns matrix2 * self
. Note that __mul__
returns self * matrix2
,
which is a different result because matrix multiplication is not
commutative.
transposed()
→ hou.Matrix2
Return the transpose of this matrix. The result is such that
self.at(i, j) == self.transposed().at(j, i)
for 0 <= i,j <= 1
.
See Wikipedia’s transpose page for more information.
inverted()
→ hou.Matrix2
Return the inverse of this matrix.
Raises hou.OperationFailed if the matrix is not invertible.
Otherwise,
(self * self.inverted()).isAlmostEqual(hou.Matrix2(1))
is True.
See Wikipedia’s invertible matrix page for more information.
determinant()
→ double
Return the determinant of the matrix.