Matrix2D
Canonical path: NemAll_Python_Geometry.Matrix2D
Representation of a 3x3 geometry transformation matrix.
This matrix is used to transform (translate, rotate and scale) 2D geometries and looks like:
- The components \(a_{11}...a_{22}\) are responsible for the rotation and scaling.
- The components \(a_{31}, a_{32}\) are responsible for the translation.
Examples:
Assuming, translation_2
is a Matrix2D that translates by 100 units in each X and Y direction.
Use Transform()
function to apply the matrix to a geometry:
Some geometry objects allow to use multiplication operator *
, like:
AddDimension
AddDimension() -> Matrix3D
IsIdentity
Check to identity matrix
Returns:
-
bool
–Return true when is matrix identity, otherwise false.
Multiply
Reflection
Reflection(axis: Axis2D)
Adds a reflection to the current matrix
Parameters:
-
axis
(Axis2D
) –Reflection axis
Examples:
A transformation consisting of translation and reflection can be defined like:
Reverse
Reverse the matrix
This method provide geometrical inverse matrix and can not be used with regular inverse 3x3 matrix calculations.
Geometrical representation:
Where \(\vec{P}\) is a point and \(A\) is this matrix.
Returns:
-
bool
–True when operation is successful, otherwise false.
Rotation
Adds a rotation to the current matrix
Parameters:
Examples:
A transformation consisting of translation and rotation can be defined like:
Scaling
Adds a scaling to the current matrix
Parameters:
-
scaleX
(float
) –Scale in X axis.
-
scaleY
(float
) –Scale in Y axis.
Examples:
A transformation consisting of translation and scaling can be defined like:
SetReflection
SetReflection(axis: Axis2D)
Set the matrix to a reflection matrix
Parameters:
-
axis
(Axis2D
) –Reflection axis
Examples:
A matrix mirroring geometries relative to Y axis can be defined like:
SetRotation
Set the matrix to a rotation matrix
Parameters:
Examples:
A matrix rotating geometries by 90° around the origin can be defined like:
SetScaling
Set the matrix to a scaling matrix
Parameters:
-
scaleX
(float
) –Scale in X axis.
-
scaleY
(float
) –Scale in Y axis.
Examples:
A matrix scaling geometries by 2 in X and 3 in Y direction can be defined like:
SetTranslation
SetTranslation(vec: Vector2D)
Set the matrix to a translation matrix
Parameters:
-
vec
(Vector2D
) –Vector of translation.
Examples:
A matrix translating geometries by 100 units in X and Y direction can be defined like:
SetValue
Set a specific matrix component to a desired value
Parameters:
-
index
(int
) –index from 0 to 8
-
value
(float
) –value to set
Returns:
-
bool
–True when operation successful (index is not out of range), otherwise false.
Translate
Translate(vec: Vector2D)
Adds a translation to the current matrix
Parameters:
-
vec
(Vector2D
) –Vector of translation.
Examples:
A transformation consisting of rotation and translation can be defined like:
__add__
Add two matrices, according to the formula:
Where \(A\) is this matrix
__getitem__
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 a matrix element at a specified position.
__iadd__
__imul__
__isub__
__mul__
Multiply two matrices, according to the formula:
Where \(A\) is this matrix
Parameters:
-
matrix
(Matrix2D
) –B matrix
Returns:
-
Matrix2D
–Product of matrices
Examples:
When:
rotation_3
is a matrix that rotates by 90° around the origin.translation_2
is a matrix that translates by 100 units in each X and Y direction.
A matrix that first rotates, then translates can be defined like: