Skip to content

Matrix2D

Class full path: NemAll_Python_Geometry.Matrix2D

Representation class for 2D matrix

Matrix data organization in memory: [0..8] indexes of array values 0,1, 3,4 - rotation, scaling and shrinking 6,7 - translation

0, 1, 2, 3, 4, 5, 6, 7, 8

All operations are correct only in geometry calculation context and can not be used for calculating with regular 4x4 matrix.

Functions

AddDimension()

Create a 3D matrix from this 2D matrix

Returns:

Type Description
Matrix3D

3D Matrix from this matrix

Determinant()

Calculate determinant

Returns:

Type Description
float

Determinant.

IsIdentity()

Check to identity matrix

Returns:

Type Description
bool

Return true when is matrix identity, otherwise false.

Multiply(matrix)

Multiple matrix with given matrix

calling " A.Multiply(B) " is identical with " A *= B "

Parameters:

Name Type Description Default
matrix Matrix2D

Matrix to be multiple with

required

Returns:

Type Description
Matrix2D

Product of matrices

Reflection(axis)

Reflection across a axis of given angle

Parameters:

Name Type Description Default
axis Axis2D

Reflection axis

required

Reverse()

Reverse matrix

This method provide geometrical inverse matrix and can not be used with regular inverse 4x4 matrix calculations.

Geometrical representation: Point3D = { Point3D * Matrix } * Matrix.Reverse()

Returns:

Type Description
bool

True when operation is successful, otherwise false.

Rotation(point, angle)

Rotate the matrix

Parameters:

Name Type Description Default
point Point2D

Point of rotation

required
angle Angle

Angle of rotation.

required

Scaling(scaleX, scaleY)

Scale the matrix

Parameters:

Name Type Description Default
scaleX float

Scale in X axis.

required
scaleY float

Scale in Y axis.

required

SetIdentity()

Initialize identity matrix

SetReflection(axis)

Initialize matrix only with reflection

Parameters:

Name Type Description Default
axis Axis2D

Reflection axis

required

SetRotation(point, angle)

Initialize matrix only with rotation

Parameters:

Name Type Description Default
point Point2D

Point of rotation.

required
angle Angle

Angle of rotation.

required

SetScaling(scaleX, scaleY)

Initialize matrix only with scaling factors

Parameters:

Name Type Description Default
scaleX float

Scale in X axis.

required
scaleY float

Scale in Y axis.

required

SetTranslation(vec)

Initialize matrix only with translation

Parameters:

Name Type Description Default
vec Vector2D

Vector of translation.

required

SetValue(index, value)

Set the matrix element at a specified position

Use this method when you don't want to catch exception by operator[].

Parameters:

Name Type Description Default
index int

Position index <0..9>

required
value float

Value for set

required

Returns:

Type Description
bool

True when operation successful (index is not out of range), otherwise false.

Translate(vec)

Translate the matrix

Parameters:

Name Type Description Default
vec Vector2D

Vector of translation.

required

__add__(matrix)

Matrix addition

Formula: Result(new matrix) = A+B A is this matrix.

Parameters:

Name Type Description Default
matrix Matrix2D

B matrix

required

Returns:

Type Description
Matrix2D

Addition of matrices

__getitem__(index)

Get the matrix element at a specified position

This method is checked and throwing Geometry::Exception when index is out of range.

Parameters:

Name Type Description Default
index int

Position index <0..9>

required

Returns:

Type Description
float

Returns an element at a specified position.

__iadd__(matrix)

Matrix addition

Formula: A += B or A = A+B A is this matrix.

Parameters:

Name Type Description Default
matrix Matrix2D

B matrix

required

Returns:

Type Description
Matrix2D

Addition of matrices

__imul__(matrix)

Matrix multiplication

Formula: A = B or A = AB A is this matrix.

Parameters:

Name Type Description Default
matrix Matrix2D

B matrix

required

Returns:

Type Description
Matrix2D

Product of matrices

__init__ overload

__init__()

Initialize

__init__(matrix)

Copy constructor

Parameters:

Name Type Description Default
matrix Matrix2D

Matrix which will be copied.

required

__isub__(matrix)

Matrix addition

Formula: A -= B or A = A-B A is this matrix.

Parameters:

Name Type Description Default
matrix Matrix2D

B matrix

required

Returns:

Type Description
Matrix2D

Addition of matrices

__mul__(matrix)

Matrix multiplication

Formula: Result(new matrix) = A*B A is this matrix.

Parameters:

Name Type Description Default
matrix Matrix2D

B matrix

required

Returns:

Type Description
Matrix2D

Product of matrices

__repr__()

Convert to string

__sub__(matrix)

Matrix addition

Formula: Result(new matrix) = A-B A is this matrix.

Parameters:

Name Type Description Default
matrix Matrix2D

B matrix

required

Returns:

Type Description
Matrix2D

Addition of matrices