Matrices¶
The geom module defines matrices in two, three and four dimensions.
All matrices store the values in row-major order, meaning that, the matrix ((1,
2), (3,4)) stores the values as (1, 2, 3, 4). This is illustrated in
the following code examples:
m=geom.Mat2(1, 2, 3, 4)
print m # will print {{1,2},{3,4}}
print m[(0,0)], m[(0,1)], m[(1,0)], m[(1,1)] # will print 1, 2, 3, 4
Matrices support arithmetic via overloaded operators. The following operations are supported:
- adding and subtracting two matrices
- negation
- multiplication of matrices
- multiplying and dividing by scalar value
The Matrix Classes¶
-
class
Mat2¶ -
class
Mat2(d00, d01, d10, d11) 2x2 real-valued matrix. The first signature creates a new identity matrix. The second signature initializes the matrix in row-major order.
-
static
Identity()¶ Returns the 2x2 identity matrix
-
static
-
class
Mat3¶ -
class
Mat3(d00, d01, d02, d10, d11, d12, d20, d21, d22) 3x3 real-valued matrix. The first signature creates a new identity matrix. The second signature initializes the matrix in row-major order.
-
static
Identity()¶ Returns the 3x3 identity matrix
-
static
-
class
Mat4¶ -
class
Mat4(d00, d01, d02, d03, d10, d11, d12, d13, d20, d21, d22, d23, d30, d31, d32, d33) 4x4 real-valued matrix. The first signature creates a new identity matrix. The second signature initializes the matrix in row-major order.
-
ExtractRotation()¶ Returns the 3x3 submatrix
-
PasteRotation(mat)¶ Set the 3x3 submatrix of the top-left corner to mat
-
ExtractTranslation()¶ Extract translation component from matrix. Only meaningful when matrix is a combination of rotation and translation matrices, otherwise the result is undefined.
-
static
Identity()¶ Returns the 4x4 identity matrix
-
Functions Operating on Matrices¶
-
Equal(lhs, rhs, epsilon=geom.EPSILON)¶ Compares the two matrices lhs and rhs and returns True, if all of the element-wise differences are smaller than epsilon. lhs and rhs must be matrices of the same dimension.
Parameters:
-
Transpose(mat)¶ Returns the transpose of mat
Parameters: mat – The matrix to be transposed
-
Invert(mat)¶ Returns the inverse of mat
Parameters: mat ( Mat2,Mat3orMat4) – The matrix to be invertedWhat happens when determinant is 0?
-
CompMultiply(lhs, rhs)¶ Returns the component-wise product of lhs and rhs. lhs and rhs must be vectors of the same dimension.
Parameters:
-
CompDivide(lhs, rhs)¶ Returns the component-wise quotient of lhs divided by rhs. lhs and rhs must be vectors of the same dimension.
Parameters:
-
Minor(mat, i, j)¶ Returns the determinant of the 2x2 matrix generated from mat by removing the ith row and jth column.
-
EulerTransformation(phi, theta, xi)¶ Returns a rotation matrix for the 3 euler angles phi, theta, and xi. The 3 angles are given in radians.