Matrix3D
Canonical path: NemAll_Python_Geometry.Matrix3D
Representation of a 4x4 geometry transformation matrix.
This matrix is used to transform (translate, rotate and scale) 3D geometries and looks like:
- The components \(a_{11}...a_{33}\) are responsible for the rotation and scaling.
- The components \(a_{41}...a_{43}\) are responsible for the translation.
Examples:
Assuming, translation_1 is a Matrix3D that translates by 100 units in each X,Y and Z direction.
Use Transform() function to apply the matrix to a geometry:
>>> geometry = Point3D(1, 1, 1)
>>> Transform(Point3D(1, 1, 1), translation_1)
Point3D(101, 101, 101)
Some geometry objects allow to use multiplication operator *, like:
Methods:
-
Determinant–Calculate determinant
-
GaussInvert–Invert the matrix using the Gauss elimination method.
-
GetScaleX–Get the scaling factor in the X direction
-
GetScaleY–Get the scaling factor in the Y direction
-
GetScaleZ–Get the scaling factor in the Z direction
-
GetScaling–Get the scaling factors in all directions
-
GetTranslationVector–Get translation part of a matrix
-
GetVectorX–Get vector X
-
GetVectorY–Get vector Y
-
GetVectorZ–Get vector Z
-
IsIdentity–Check to identity matrix
-
LaplaceTransform–Transformation matrix by Laplace
-
Multiply–Multiply this matrix with another one, according to the formula:
-
ReduceZDimension–Create a 2D matrix from this 3D matrix
-
Reflection–Adds a reflection to the current matrix
-
Reverse–Reverse the matrix
-
Rotation–Adds a rotation to the current matrix
-
Scaling–Adds a scaling to the current matrix
-
SetIdentity–Set the matrix to identity
-
SetProjection–Set the matrix to a projection matrix
-
SetReflection–Set the matrix to a reflection matrix
-
SetRotation–Overloaded function. See individual overloads.
-
SetScaling–Initialize matrix only with scaling factors
-
SetTranslation–Set the matrix to a translation matrix
-
SetValue–Set a specific matrix component to a value
-
SetValues–Sets each matrix-element
-
Translate–Adds a translation to the current matrix
-
Transpose–Transpose the matrix
-
__add__–Add two matrices, according to the formula:
-
__eq__–Comparison of matrices.
-
__getitem__–Get the matrix element at a specified position
-
__iadd__–Add two matrices in place, according to the formula:
-
__imul__–Multiply two matrices in place, according to the formula:
-
__init__–Overloaded function. See individual overloads.
-
__isub__–Subtract two matrices in place, according to the formula:
-
__mul__–Multiply two matrices, according to the formula:
-
__repr__–Convert to string
-
__sub__–Subtract two matrices, according to the formula:
GaussInvert
Invert the matrix using the Gauss elimination method.
Inverted matrix reverses the transformation applied by the original matrix.
Returns:
-
bool–True when operation is successful, otherwise false.
GetScaleX
GetScaleY
GetScaleZ
GetScaling
GetScaling() -> tuple[float, float, float]
Get the scaling factors in all directions
Returns:
-
float–Scaling factor in the X direction
-
float–Scaling factor in the Y direction
-
float–Scaling factor in the Z direction
Examples:
scale is a Matrix3D that scales by 2 in the X direction, 3 in the Y direction and 4 in the Z direction.
GetTranslationVector
GetTranslationVector() -> Vector3D
Get translation part of a matrix
Returns:
-
Vector3D–The vector of translation
Examples:
translation_1 is a Matrix3D that translates by 100 units in each X,Y and Z direction.
GetVectorX
GetVectorX() -> Vector3D
Get vector X
Returns:
-
Vector3D–Vector X
Examples:
rotation_1 is a Matrix3D that rotates by 90° around the Z axis.
GetVectorY
GetVectorY() -> Vector3D
Get vector Y
Returns:
-
Vector3D–Vector Y
Examples:
rotation_1 is a Matrix3D that rotates by 90° around the Z axis.
GetVectorZ
GetVectorZ() -> Vector3D
Get vector Z
Returns:
-
Vector3D–Vector Z
Examples:
rotation_2 is a Matrix3D that rotates by 90° around the X axis.
IsIdentity
Multiply
ReduceZDimension
ReduceZDimension() -> Matrix2D
Create a 2D matrix from this 3D matrix
Returns:
-
Matrix2D–a 2D matrix from this 3D matrix
Examples:
rotation_1 is a Matrix3D that rotates by 90° around the Z axis. When Z dimension is reduced,
it can also be applied on 2D geometries:
Reflection
Reflection(plane: Plane3D)
Adds a reflection to the current matrix
Parameters:
-
plane(Plane3D) –Reflection plane
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 4x4 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:
Returns:
-
bool–True when successful, otherwise false.
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.
-
scaleZ(float) –Scale in Z axis.
Examples:
A transformation consisting of translation and scaling can be defined like:
SetProjection
SetProjection(proj: eProjectionMatrixType)
Set the matrix to a projection matrix
A projection matrix rotates the geometry, so that the desired side is facing upwards.
Parameters:
-
proj(eProjectionMatrixType) –Projection type
Examples:
A projection matrix of type FRONT_2D rotates the geometry around X axis by -90°, so that the front
side is facing upwards:
>>> front_projection = Matrix3D()
>>> front_projection.SetProjection(eProjectionMatrixType.FRONT_2D)
>>> front_projection.GetVectorX(), front_projection.GetVectorY(), front_projection.GetVectorZ()
(Vector3D(1, 0, 0), Vector3D(0, 0, -1), Vector3D(0, 1, 0))
The matrix only rotates the geometry. No translation or scaling is applied:
SetReflection
SetReflection(plane: Plane3D)
Set the matrix to a reflection matrix
Parameters:
-
plane(Plane3D) –Reflection plane
Examples:
A matrix reflecting geometries relative to YZ plane can be defined like:
SetRotation
overloaded
Set the matrix to a rotation matrix by axis and angle
Parameters:
Returns:
-
bool–True when successful, otherwise false.
Examples:
A matrix rotating geometries around X axis by 90° can be defined like:
Set the matrix to a rotation matrix by start and end vector
Parameters:
-
startDirection(Vector3D) –direction vector for start of rotation.
-
endDirection(Vector3D) –direction vector for end of rotation.
Returns:
-
bool–True when successful, otherwise false.
Examples:
A matrix rotating geometries around X axis by 90° can be defined like:
SetScaling
Initialize matrix only with scaling factors
Parameters:
-
scaleX(float) –Scale in X axis.
-
scaleY(float) –Scale in Y axis.
-
scaleZ(float) –Scale in Z axis.
SetTranslation
SetTranslation(vec: Vector3D)
Set the matrix to a translation matrix
Parameters:
-
vec(Vector3D) –Vector of translation.
Examples:
A matrix translating geometries by 100 units in each X,Y and Z direction can be defined like:
SetValue
Set a specific matrix component to a value
Parameters:
-
index(int) –Position index <0..15>
-
value(float) –Value to set
Returns:
-
bool–True when operation successful (index is not out of range), otherwise false.
SetValues
SetValues(
v00: float,
v01: float,
v02: float,
v03: float,
v10: float,
v11: float,
v12: float,
v13: float,
v20: float,
v21: float,
v22: float,
v23: float,
v30: float,
v31: float,
v32: float,
v33: float,
)
Sets each matrix-element
Parameters:
-
v00(float) –first row, first element
-
v01(float) –first row, second element
-
v02(float) –first row, third element
-
v03(float) –first row, fourth element
-
v10(float) –second row, first element
-
v11(float) –second row, second element
-
v12(float) –second row, third element
-
v13(float) –second row, fourth element
-
v20(float) –third row, first element
-
v21(float) –third row, second element
-
v22(float) –third row, third element
-
v23(float) –third row, fourth element
-
v30(float) –fourth row, first element
-
v31(float) –fourth row, second element
-
v32(float) –fourth row, third element
-
v33(float) –fourth row, fourth element
Translate
Translate(vec: Vector3D)
Adds a translation to the current matrix
Parameters:
-
vec(Vector3D) –Vector of translation.
Examples:
A transformation consisting of rotation and translation can be defined like:
Transpose
Transpose the matrix
All transform-services multiply transformation-matrix from the right side. If you need the result as it would be multiplication from the left side you need the transposed matrix.
The matrix is transposed like:
__add__
__eq__
__eq__(matrix: Matrix3D) -> bool
Comparison of matrices.
Be careful, this method work without tolerance!
Parameters:
-
matrix(Matrix3D) –matrix to be compared.
Returns:
-
bool–True when matrices are equal, otherwise false.
__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..15>
Returns:
-
float–Returns a matrix element at a specified position.
__iadd__
__imul__
__init__
overloaded
Initialize
__init__(proj: eProjectionMatrixType)
Constructor
Create a matrix for the required projection.
Parameters:
-
proj(eProjectionMatrixType) –The required projection
__init__(matrix: Matrix3D)
__init__(
v00: float,
v01: float,
v02: float,
v03: float,
v10: float,
v11: float,
v12: float,
v13: float,
v20: float,
v21: float,
v22: float,
v23: float,
v30: float,
v31: float,
v32: float,
v33: float,
)
Constructor setting each matrix-element
Parameters:
-
v00(float) –first row, first element
-
v01(float) –first row, second element
-
v02(float) –first row, third element
-
v03(float) –first row, fourth element
-
v10(float) –second row, first element
-
v11(float) –second row, second element
-
v12(float) –second row, third element
-
v13(float) –second row, fourth element
-
v20(float) –third row, first element
-
v21(float) –third row, second element
-
v22(float) –third row, third element
-
v23(float) –third row, fourth element
-
v30(float) –fourth row, first element
-
v31(float) –fourth row, second element
-
v32(float) –fourth row, third element
-
v33(float) –fourth row, fourth element
Constructor
Parameters:
-
valuesinrows(list) –matrix values by rows as Python list
__isub__
__mul__
Multiply two matrices, according to the formula:
Where \(A\) is this matrix
Parameters:
-
matrix(Matrix3D) –B matrix
Returns:
-
Matrix3D–Product of matrices
Examples:
When:
rotation_1is a Matrix3D that rotates by 90° around the Z axis.rotation_2is a Matrix3D that rotates by 90° around the X axis.translation_1is a Matrix3D that translates by 100 units in each X,Y and Z direction.
A matrix, that first rotates by 90° around the Z axis, then by 90° around the X axis and finally translates by 100 units in each X,Y and Z direction can be defined like: