Skip to content

Matrix2D

Canonical 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.

AddDimension

AddDimension() -> Matrix3D

Create a 3D matrix from this 2D matrix

Returns:

  • Matrix3D

    3D Matrix from this matrix

Determinant

Determinant() -> float

Calculate determinant

Returns:

  • float

    Determinant.

IsIdentity

IsIdentity() -> bool

Check to identity matrix

Returns:

  • bool

    Return true when is matrix identity, otherwise false.

Multiply

Multiply(matrix: Matrix2D) -> Matrix2D

Multiple matrix with given matrix

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

Parameters:

  • matrix (Matrix2D) –

    Matrix to be multiple with

Returns:

Reflection

Reflection(axis: Axis2D)

Reflection across a axis of given angle

Parameters:

  • axis (Axis2D) –

    Reflection axis

Reverse

Reverse() -> bool

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:

  • bool

    True when operation is successful, otherwise false.

Rotation

Rotation(point: Point2D, angle: Angle)

Rotate the matrix

Parameters:

  • point (Point2D) –

    Point of rotation

  • angle (Angle) –

    Angle of rotation.

Scaling

Scaling(scaleX: float, scaleY: float)

Scale the matrix

Parameters:

  • scaleX (float) –

    Scale in X axis.

  • scaleY (float) –

    Scale in Y axis.

SetIdentity

SetIdentity()

Initialize identity matrix

SetReflection

SetReflection(axis: Axis2D)

Initialize matrix only with reflection

Parameters:

  • axis (Axis2D) –

    Reflection axis

SetRotation

SetRotation(point: Point2D, angle: Angle)

Initialize matrix only with rotation

Parameters:

  • point (Point2D) –

    Point of rotation.

  • angle (Angle) –

    Angle of rotation.

SetScaling

SetScaling(scaleX: float, scaleY: float)

Initialize matrix only with scaling factors

Parameters:

  • scaleX (float) –

    Scale in X axis.

  • scaleY (float) –

    Scale in Y axis.

SetTranslation

SetTranslation(vec: Vector2D)

Initialize matrix only with translation

Parameters:

  • vec (Vector2D) –

    Vector of translation.

SetValue

SetValue(index: int, value: float) -> bool

Set the matrix element at a specified position

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

Parameters:

  • index (int) –

    Position index <0..9>

  • value (float) –

    Value for set

Returns:

  • bool

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

Translate

Translate(vec: Vector2D)

Translate the matrix

Parameters:

  • vec (Vector2D) –

    Vector of translation.

__add__

__add__(matrix: Matrix2D) -> Matrix2D

Matrix addition

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

Parameters:

Returns:

__getitem__

__getitem__(index: int) -> float

Get the matrix element at a specified position

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

Parameters:

  • index (int) –

    Position index <0..9>

Returns:

  • float

    Returns an element at a specified position.

__iadd__

__iadd__(matrix: Matrix2D) -> Matrix2D

Matrix addition

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

Parameters:

Returns:

__imul__

__imul__(matrix: Matrix2D) -> Matrix2D

Matrix multiplication

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

Parameters:

Returns:

__init__ overloaded

__init__()

Initialize

__init__(matrix: Matrix2D)

Copy constructor

Parameters:

  • matrix (Matrix2D) –

    Matrix which will be copied.

__isub__

__isub__(matrix: Matrix2D) -> Matrix2D

Matrix addition

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

Parameters:

Returns:

__mul__

__mul__(matrix: Matrix2D) -> Matrix2D

Matrix multiplication

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

Parameters:

Returns:

__repr__

__repr__() -> str

Convert to string

__sub__

__sub__(matrix: Matrix2D) -> Matrix2D

Matrix addition

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

Parameters:

Returns:

Placeholder