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:
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_1
is a Matrix3D that rotates by 90° around the Z axis.rotation_2
is a Matrix3D that rotates by 90° around the X axis.translation_1
is 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: