Matrix44#

class ansys.geometry.core.math.matrix.Matrix44(shape, dtype=float, buffer=None, offset=0, strides=None, order=None)#

Bases: Matrix

Provides 4x4 matrix representation.

Parameters:
inputndarray | RealSequence | Matrix, default: DEFAULT_MATRIX44

Matrix arguments as a np.ndarray class.

Overview#

create_translation

Create a matrix representing the specified translation.

create_rotation

Create a matrix representing the specified rotation.

is_translation

Check if the matrix represents a translation.

Import detail#

from ansys.geometry.core.math.matrix import Matrix44

Method detail#

classmethod Matrix44.create_translation(translation: ansys.geometry.core.math.vector.Vector3D) Matrix44#

Create a matrix representing the specified translation.

Parameters:
translationVector3D

The translation vector representing the translation. The components of the vector should be in meters.

Returns:
Matrix44

A 4x4 matrix representing the translation.

Examples

>>> translation_vector = Vector3D(1.0, 2.0, 3.0)
>>> translation_matrix = Matrix44.create_translation(translation_vector)
>>> print(translation_matrix)
[[1. 0. 0. 1.]
 [0. 1. 0. 2.]
 [0. 0. 1. 3.]
 [0. 0. 0. 1.]]
Matrix44.is_translation(including_identity: bool = False) bool#

Check if the matrix represents a translation.

This method checks if the matrix represents a translation transformation. A translation matrix has the following form:

[1 0 0 tx] [0 1 0 ty] [0 0 1 tz] [0 0 0 1]

Parameters:
including_identitybool, optional

If True, the method will return True for the identity matrix as well. If False, the method will return False for the identity matrix.

Returns:
bool

True if the matrix represents a translation, False otherwise.

Examples

>>> matrix = Matrix44([[1, 0, 0, 5], [0, 1, 0, 3], [0, 0, 1, 2], [0, 0, 0, 1]])
>>> matrix.is_translation()
True
>>> identity_matrix = Matrix44([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]])
>>> identity_matrix.is_translation()
False
>>> identity_matrix.is_translation(including_identity=True)
True
classmethod Matrix44.create_rotation(direction_x: ansys.geometry.core.math.vector.Vector3D, direction_y: ansys.geometry.core.math.vector.Vector3D, direction_z: ansys.geometry.core.math.vector.Vector3D = None) Matrix44#

Create a matrix representing the specified rotation.

Parameters:
direction_xVector3D

The X direction vector.

direction_yVector3D

The Y direction vector.

direction_zVector3D, optional

The Z direction vector. If not provided, it will be calculated as the cross product of direction_x and direction_y.

Returns:
Matrix44

A 4x4 matrix representing the rotation.

Examples

>>> direction_x = Vector3D(1.0, 0.0, 0.0)
>>> direction_y = Vector3D(0.0, 1.0, 0.0)
>>> rotation_matrix = Matrix44.create_rotation(direction_x, direction_y)
>>> print(rotation_matrix)
[[1. 0. 0. 0.]
[0. 1. 0. 0.]
[0. 0. 1. 0.]
[0. 0. 0. 1.]]