This document is for OpenStructure version 2.3.1, the latest version is 2.7 !

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

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

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, Mat3 or Mat4) – The matrix to be inverted

What 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:
Det(mat)

Returns the determinant of mat :param mat: A matrix :type mat: Mat2, Mat3 or Mat4

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.

AxisRotation(axis, angle)

Returns a rotation matrix that represents a rotation of angle around the axis.

Parameters:
  • axis (Vec3) – The rotation axis. Will be normalized

  • angle – Rotation angle (radians) in clockwise direction when looking down the axis.

OrthogonalVector(vec)

Get arbitrary vector orthogonal to vec. The returned vector is of length 1, except when vec is a zero vector. In that case, the returned vector is (0, 0, 0).

Parameters:

vec (Vec3) – A vector of arbitrary length

Search

Enter search terms or a module, class or function name.

Contents

Documentation is available for the following OpenStructure versions:

dev / 2.7 / 2.6 / 2.5 / 2.4 / (Currently viewing 2.3.1) / 2.3 / 2.2 / 2.1 / 2.0 / 1.9 / 1.8 / 1.7.1 / 1.7 / 1.6 / 1.5 / 1.4 / 1.3 / 1.2 / 1.11 / 1.10 / 1.1

This documentation is still under heavy development!
If something is missing or if you need the C++ API description in doxygen style, check our old documentation for further information.