rdmc.mathlib.geom#

This module provides class and methods for dealing with 3D geometry operations.

rdmc.mathlib.geom.get_centroid(coords: array, keepdims=False) array#

Get the centroid given the coords of each item.

Parameters:
  • coords (np.array) – The 3D coordinates in numpy array with a size of N x 3.

  • keepdims (bool) – Defaults to False (export 1D array); otherwise output an array of a size of 1 x 3.

Returns:

np.array – 1D array indicate the coordinates of the centroid.

rdmc.mathlib.geom.get_distances_from_a_point(coords: array, pos: array, keepdims: bool = False)#

Get the Euclidiean distance to a point for all elements.

Parameters:
  • coords (np.array) – The 3D coordinates in numpy array with a size of N x 3.

  • pos (np.array) – The coordinates of the point.

  • keepdims (bool) – Defaults to False (export 1D array); otherwise output an array of a size of 1 x 3.

Returns:

np.array – 1D array indicate the distances.

rdmc.mathlib.geom.get_mass_center(coords: array, atommasses: Iterable, keepdims=False) array#

Get the mass center given the coords of each item and its corresponding mass.

Parameters:
  • coords (np.array) – The 3D coordinates in numpy array with a size of N x 3.

  • atommasses (Iterable) – A list or an array of mass values.

  • keepdims (bool) – Defaults to False (export 1D array); otherwise output an array of a size of 1 x 3.

Returns:

np.array – 1D array indicate the coordinates of the mass center.

rdmc.mathlib.geom.get_max_distance_from_center(coords: array) float#

Get the maximum distance from the center of a set of coordinates

Parameters:

coords (np.array) – The 3D coordinates in numpy array with a size of N x 3.

Returns:

float – The distance between the center and the farthest item.

rdmc.mathlib.geom.get_weighted_center(coords: array, weights: Iterable, keepdims=False) array#

Get the mass center given the coords of each item and its corresponding weight.

Parameters:
  • coords (np.array) – The 3D coordinates in numpy array with a size of N x 3.

  • weights (Iterable) – A list or an array of weights corresponding to each element.

  • keepdims (bool) – Defaults to False (export 1D array); otherwise output an array of a size of 1 x 3.

Returns:

np.array – 1D array indicate the coordinates of the mass center.

rdmc.mathlib.geom.rotate(coords: array, angles: array, degrees: bool = False, about_center: bool = False, about: array | None = None)#

Rotate the coordinates according to the angles about the x, y, and z axes. The rotation is about the origin, but there are a few options about choosing the about location.

Parameters:
  • coords (np.array) – The 3D coordinates in numpy array with a size of \(N \times 3\).

  • angles (np.array) – An array with a size of (1,3) indicates the rotation angles about the x, y, and z axes, respectively.

  • degrees (bool) – If the angles are defined as degrees. Defaults to False.

  • about_center (bool) – Whether to rotate the coordinates about their center. Defaults to False. Note about_center cannot be assigned simultaneously with about.

  • about (np.array) – The coordinate that the rotation is about. Should be a vector with a length of 3. It is defaults to None, rotating about the origin. about cannot be specified along with about_center.

Returns:

np.array – coordinates after the rotation.

rdmc.mathlib.geom.translate(coords: array, tran_vec: array) array#

Translate the coordinates according to the tran_vec vector.

Parameters:
  • coords (np.array) – The 3D coordinates in numpy array with a size of N x 3.

  • tran_vec (np.array) – A vector indicate the direction and the magnitude of the translational operation. It should be a numpy array with a size of (3,) or (1,3).

Returns:

np.array – An numpy array with the same size as the original coords.

rdmc.mathlib.geom.translate_centroid(coords: array, new_ctr: array = array([0., 0., 0.]))#

Translate the coordinates according to the tran_vec vector.

Parameters:
  • coords (np.array) – The 3D coordinates in numpy array with a size of N x 3.

  • new_ctr (np.array) – A vector indicate the new position of the centroid. It should be a numpy array with a size of (3,) or (1,3). By defaults, the centroid will be moved to the origin.

Returns:

np.array – An numpy array with the same size as the original coords.