Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Fixed order in function `cartesian_to_spherical` (#2168)

Viicos85e733739e95
diff --git a/manim/mobject/geometry.py b/manim/mobject/geometry.py
index 5ffd1936d..f4b1be030 100644
--- a/manim/mobject/geometry.py
+++ b/manim/mobject/geometry.py
@@ -179,16 +179,16 @@ class TipableVMobject(VMobject, metaclass=ConvertToOpenGL):
anchor = self.get_end()
angles = cartesian_to_spherical(handle - anchor)
tip.rotate(
- angles[2] - PI - tip.tip_angle,
+ angles[1] - PI - tip.tip_angle,
) # Rotates the tip along the azimuthal
if not hasattr(self, "_init_positioning_axis"):
axis = [
- np.sin(angles[2]),
- -np.cos(angles[2]),
+ np.sin(angles[1]),
+ -np.cos(angles[1]),
0,
] # Obtains the perpendicular of the tip
tip.rotate(
- -angles[1] + PI / 2,
+ -angles[2] + PI / 2,
axis=axis,
) # Rotates the tip along the vertical wrt the axis
self._init_positioning_axis = axis
diff --git a/manim/utils/space_ops.py b/manim/utils/space_ops.py
index f9bc29c78..7d9c54cfa 100644
--- a/manim/utils/space_ops.py
+++ b/manim/utils/space_ops.py
@@ -769,7 +769,7 @@ def cartesian_to_spherical(vec: Sequence[float]) -> np.ndarray:
r = norm
phi = np.arccos(vec[2] / r)
theta = np.arctan2(vec[1], vec[0])
- return np.array([r, phi, theta])
+ return np.array([r, theta, phi])
def spherical_to_cartesian(spherical: Sequence[float]) -> np.ndarray:
diff --git a/tests/test_space_ops.py b/tests/test_space_ops.py
index 42d34b641..f6ceeef41 100644
--- a/tests/test_space_ops.py
+++ b/tests/test_space_ops.py
@@ -8,6 +8,6 @@ def test_polar_coords():
b = (2, np.pi / 2, np.pi / 2)
assert all(
np.round(cartesian_to_spherical(a), 4)
- == np.round([2 ** 0.5, np.pi / 2, np.pi / 4], 4),
+ == np.round([2 ** 0.5, np.pi / 4, np.pi / 2], 4),
)
assert all(np.round(spherical_to_cartesian(b), 4) == np.array([0, 2, 0]))