def test_to_parent_to_local(self): origin = (np.random.random(3) - 0.5) * 100 other_coordinate_system = Cartesian(origin=origin) axis = (np.random.random(3) - 0.5) * 100 angle = (np.random.random() - 0.5) * 100 other_coordinate_system.rotate_axis_angle(axis, angle) point_global = (np.random.random(3) - 0.5) * 100 point_local = other_coordinate_system.to_local(point_global) point_global2 = other_coordinate_system.to_parent(point_local) np.testing.assert_allclose(point_global2, point_global, atol=np.finfo(float).eps) point_local = (np.random.random(3) - 0.5) * 100 point_global = other_coordinate_system.to_parent(point_local) point_local_2 = other_coordinate_system.to_local(point_global) np.testing.assert_allclose(point_local_2, point_local, atol=np.finfo(float).eps)
def arc_between_two_points(coordinate_system, point1, point2, radius=1, right=True): global_point1 = coordinate_system.to_parent(point1) global_point2 = coordinate_system.to_parent(point2) direction = point2 - point1 distance = np.sqrt(np.dot(direction, direction)) arc_coordinate_system = Cartesian(basis=np.copy(coordinate_system.basis), origin=np.copy(global_point1), name='Arc coordinate_system') r_theta_phi = transforms.cartesian_to_spherical(direction) arc_coordinate_system.rotate_axis_angle([0, 0, 1], r_theta_phi[2]) arc_coordinate_system.rotate_axis_angle([0, 1, 0], r_theta_phi[1] + np.pi/2) x_offset = -distance / 2 y_offset = np.sqrt(radius**2 - x_offset**2) if right: y_offset *= -1 arc_coordinate_system.origin = arc_coordinate_system.to_parent([x_offset, y_offset, 0]) local_point1 = arc_coordinate_system.to_local(global_point1) local_point2 = arc_coordinate_system.to_local(global_point2) start = transforms.cartesian_to_spherical(local_point1)[2] stop = transforms.cartesian_to_spherical(local_point2)[2] if not right: start = 2 * np.pi - start stop = 2 * np.pi - stop path = Arc(coordinate_system=arc_coordinate_system, a=radius, b=radius, start=start, stop=stop, right=right) return path