rotate_vector_collection

halotools.utils.rotate_vector_collection(rotation_matrices, vectors, optimize=False)[source]

Given a collection of rotation matrices and a collection of n-dimensional vectors, apply an asscoiated matrix to rotate corresponding vector(s).

Parameters:
rotation_matricesndarray

The options are: 1.) array of shape (npts, ndim, ndim) storing a collection of rotation matrices. 2.) array of shape (ndim, ndim) storing a single rotation matrix

vectorsndarray

The corresponding options for above are: 1.) array of shape (npts, ndim) storing a collection of ndim-dimensional vectors 2.) array of shape (npts, ndim) storing a collection of ndim-dimensional vectors

Returns:
rotated_vectorsndarray

Numpy array of shape (npts, ndim) storing a collection of ndim-dimensional vectors

Notes

This function is set up to preform either rotation operations on a single collection of vectors, either applying a single rotation matrix to all vectors in the collection, or applying a unique rotation matrix to each vector in the set.

The behavior of the function is determined by the arguments supplied by the user.

Examples

In this example, we’ll randomly generate two sets of unit-vectors, v0 and v1. We’ll use the rotation_matrices_from_vectors function to generate the rotation matrices that rotate each v0 into the corresponding v1. Then we’ll use the rotate_vector_collection function to apply each rotation, and verify that we recover each of the v1.

>>> from halotools.utils.rotations3d import rotation_matrices_from_vectors
>>> from halotools.utils import normalized_vectors
>>> npts, ndim = int(1e4), 3
>>> v0 = normalized_vectors(np.random.random((npts, ndim)))
>>> v1 = normalized_vectors(np.random.random((npts, ndim)))
>>> rotation_matrices = rotation_matrices_from_vectors(v0, v1)
>>> v2 = rotate_vector_collection(rotation_matrices, v0)
>>> assert np.allclose(v1, v2)