Example #1
0
 def test_to_spherical_single_point(self):
     xyz = [1, 0, 0]
     np.testing.assert_allclose(cartesian_to_spherical(xyz), [1, np.pi / 2, 0], atol=np.finfo(float).eps)
     xyz = [0, 1, 0]
     np.testing.assert_allclose(cartesian_to_spherical(xyz), [1, np.pi / 2, np.pi / 2], atol=np.finfo(float).eps)
     xyz = [0, 0, 0]
     np.testing.assert_allclose(cartesian_to_spherical(xyz), [0, 0, 0], atol=np.finfo(float).eps)
Example #2
0
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
Example #3
0
 def test_to_cylindrical_and_back_many_points(self):
     points_num = 100
     xyz = ((np.random.random(points_num * 3) - 0.5) * 200).reshape((points_num, 3))
     rpz = cartesian_to_cylindrical(xyz)
     np.testing.assert_allclose(cylindrical_to_cartesian(rpz), xyz)
     rtp = cylindrical_to_spherical(rpz)
     np.testing.assert_allclose(cartesian_to_spherical(xyz), rtp)
     np.testing.assert_allclose(spherical_to_cylindrical(rtp), rpz)
     np.testing.assert_allclose(spherical_to_cartesian(rtp), xyz)
Example #4
0
def helix_between_two_points(coordinate_system, point1, point2, radius=1, loops=1, right=True):
    direction = point2 - point1
    distance = np.sqrt(np.dot(direction, direction))
    origin = coordinate_system.to_parent(point1)
    helix_coordinate_system = Cartesian(basis=np.copy(coordinate_system.basis), origin=np.copy(origin),
                                        name='Helix coordinate system')
    r_theta_phi = transforms.cartesian_to_spherical(direction)
    helix_coordinate_system.rotate_axis_angle([0, 0, 1], r_theta_phi[2])
    helix_coordinate_system.rotate_axis_angle([0, 1, 0], r_theta_phi[1])
    pitch = distance / int(loops)
    name = 'Right Helix' if right else 'Left Helix'
    path = Helix(name=name, coordinate_system=helix_coordinate_system,
                 radius=radius, pitch=pitch, start=0, stop=np.pi * 2 * int(loops), right=right)
    return path
 def vector_field(self, xyz):
     rtp = gt.cartesian_to_spherical(xyz)
     rtp[np.where(rtp[:, 0] < self.r), 0] = self.r
     r = rtp[:, 0] ** 2
     r = np.array([r, r, r]).T
     return self.q * xyz / r
 def scalar_field(self, xyz):
     rtp = gt.cartesian_to_spherical(xyz)
     rtp[np.where(rtp[:, 0] < self.r), 0] = self.r
     return self.q / rtp[:, 0]