mpacts.geometrygenerators. transformations

Class to transform points

In order to be able to use this module import it like this:

import mpacts.geometrygenerators.transformations
#or assign it to a shorter name
import mpacts.geometrygenerators.transformations as tra
mpacts.geometrygenerators.transformations.angle_to_quaternion(angle, axis)
mpacts.geometrygenerators.transformations.crop_to_beam(v, center, x, y, z, return_excluded=False)

crops a set of positions v to a specified beam with center, x,y,and z side lengths

mpacts.geometrygenerators.transformations.crop_to_beam_indices(v, center, x, y, z, return_excluded=False)

crops a set of positions v to a specified beam with center, x,y,and z side lengths, returning the indices of the cropped positions

mpacts.geometrygenerators.transformations.crop_to_sphere(v, center, radius, return_excluded=False)

crops a set of positions v to a specified sphere with center and a radius

mpacts.geometrygenerators.transformations.crop_to_sphere_indices(v, center, radius, return_excluded=False)

crops a set of positions v to a specified sphere with center and a radius

mpacts.geometrygenerators.transformations.get_axis_rotation_matrix(direction, angle)

Create a rotation matrix corresponding to the rotation around a general axis by a specified angle.

R = dd^T + cos(a) (I - dd^T) + sin(a) skew(d)

Parameters:
angle : float a (in radian!) direction : array d
mpacts.geometrygenerators.transformations.get_principal_basis(x)
mpacts.geometrygenerators.transformations.get_skew(vec)
mpacts.geometrygenerators.transformations.multiply_quaternions(r, q)
mpacts.geometrygenerators.transformations.project_to_beam(v, center, x, y, z, use_as_margin=False)

vertices from v outside of a beam are projected to the beam’s wall closest to the beam if use_as_margin, we will project with x,y,z distance from the min / max

mpacts.geometrygenerators.transformations.project_to_circle(v, center, radius)
mpacts.geometrygenerators.transformations.quaternion_from_matrix(matrix, isprecise=False)

Return quaternion from rotation matrix.

If isprecise is True, the input matrix is assumed to be a precise rotation matrix and a faster algorithm is used.

>>> q = quaternion_from_matrix(numpy.identity(4), True)
>>> numpy.allclose(q, [1, 0, 0, 0])
True
>>> q = quaternion_from_matrix(numpy.diag([1, -1, -1, 1]))
>>> numpy.allclose(q, [0, 1, 0, 0]) or numpy.allclose(q, [0, -1, 0, 0])
True
>>> R = rotation_matrix(0.123, (1, 2, 3))
>>> q = quaternion_from_matrix(R, True)
>>> numpy.allclose(q, [0.9981095, 0.0164262, 0.0328524, 0.0492786])
True
>>> R = [[-0.545, 0.797, 0.260, 0], [0.733, 0.603, -0.313, 0],
...      [-0.407, 0.021, -0.913, 0], [0, 0, 0, 1]]
>>> q = quaternion_from_matrix(R)
>>> numpy.allclose(q, [0.19069, 0.43736, 0.87485, -0.083611])
True
>>> R = [[0.395, 0.362, 0.843, 0], [-0.626, 0.796, -0.056, 0],
...      [-0.677, -0.498, 0.529, 0], [0, 0, 0, 1]]
>>> q = quaternion_from_matrix(R)
>>> numpy.allclose(q, [0.82336615, -0.13610694, 0.46344705, -0.29792603])
True
>>> R = random_rotation_matrix()
>>> q = quaternion_from_matrix(R)
>>> is_same_transform(R, quaternion_matrix(q))
True
>>> is_same_quaternion(quaternion_from_matrix(R, isprecise=False),
...                    quaternion_from_matrix(R, isprecise=True))
True
>>> R = euler_matrix(0.0, 0.0, numpy.pi/2.0)
>>> is_same_quaternion(quaternion_from_matrix(R, isprecise=False),
...                    quaternion_from_matrix(R, isprecise=True))
True
mpacts.geometrygenerators.transformations.quaternion_to_rotation_matrix(q)
mpacts.geometrygenerators.transformations.rand_quaternion(deflection=1.0, randnums=None)
mpacts.geometrygenerators.transformations.rand_rotation_matrix(deflection=1.0, randnums=None)

Creates a random rotation matrix.

deflection: the magnitude of the rotation. For 0, no rotation; for 1, competely random rotation. Small deflection => small perturbation. randnums: 3 random numbers in the range [0, 1]. If None, they will be auto-generated.

mpacts.geometrygenerators.transformations.rotate(R, v)

rotate the vectors in v by rotation matrix R v is npoints x 3

mpacts.geometrygenerators.transformations.rotate_to_principal(x)
mpacts.geometrygenerators.transformations.scale(x, scale_factor)
mpacts.geometrygenerators.transformations.translate(t, v)

translate the vectors in v by vector t