def test_get_rotation_matrix(self): v1 = np.random.rand(3) v2 = np.random.rand(3) v1 = v1 / np.linalg.norm(v1) v2 = v2 / np.linalg.norm(v2) rot = helpers.get_rotation_matrix(v1, v2) v2_bis = rot @ v1.T for i in range(3): self.assertAlmostEqual(v2[i], v2_bis[i])
def get_ZLOS(angle, scoords, gcoords, this_gmass, this_gZ, this_gsml, lkernel, kbins): vector = get_cartesian_from_spherical(angle) rot = get_rotation_matrix(vector) this_scoords = (rot @ scoords.T).T this_gcoords = (rot @ gcoords.T).T Z_los_SD = get_Z_LOS(this_scoords, this_gcoords, this_gmass, this_gZ, this_gsml, lkernel, kbins)*conv return Z_los_SD
def test_rotation_against_quat(self): """ Test that rotating with quaternion or matrix is equivalent""" v1 = np.random.rand(3) v2 = np.random.rand(3) v1 = v1 / np.linalg.norm(v1) v2 = v2 / np.linalg.norm(v2) rot = helpers.get_rotation_matrix(v1, v2) vector, angle = helpers.get_rotation_vector_and_angle(v1, v2) quat = Quaternion(vector=vector, angle=angle).unit() rot_quat = quat.basis() for x_row, y_row in zip(rot, rot_quat): for a, b in zip(x_row, y_row): self.assertAlmostEqual(a, b)
def rotation_matrix_from_alpha_delta(source, sat, t): Cu = source.unit_topocentric_function(sat, t) Su = np.array([1, 0, 0]) r = helpers.get_rotation_matrix(Cu, Su) return r