From 77636c06c1087eda7165e9c50f07ffbac735353d Mon Sep 17 00:00:00 2001 From: Daud Ibrahim Hassan <157341340+daudibrahimhasan@users.noreply.github.com> Date: Sun, 21 Jun 2026 01:11:53 +0600 Subject: [PATCH 1/2] Fix docstring for cartesian_to_spherical to match return order --- manim/utils/space_ops.py | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/manim/utils/space_ops.py b/manim/utils/space_ops.py index 0aa57b93c6..b1763903ee 100644 --- a/manim/utils/space_ops.py +++ b/manim/utils/space_ops.py @@ -809,21 +809,25 @@ def earclip_triangulation(verts: np.ndarray, ring_ends: list) -> list: def cartesian_to_spherical(vec: Vector3DLike) -> np.ndarray: - """Returns an array of numbers corresponding to each - polar coordinate value (distance, phi, theta). + """Returns an array of numbers corresponding to each + spherical coordinate value (distance, theta, phi). - Parameters - ---------- - vec - A numpy array or a sequence of floats ``[x, y, z]``. - """ - norm = np.linalg.norm(vec) - if norm == 0: - return np.zeros(3) - r = norm - phi = np.arccos(vec[2] / r) - theta = np.arctan2(vec[1], vec[0]) - return np.array([r, theta, phi]) + Parameters + ---------- + vec + A numpy array or a sequence of floats ``[x, y, z]``. + + Returns + ------- + :class:`numpy.ndarray` + An array of three floats ``[r, theta, phi]`` where: + + r - The distance between the point and the origin. + + theta - The azimuthal angle of the point to the positive x-axis. + + phi - The vertical angle of the point to the positive z-axis. + """ def spherical_to_cartesian(spherical: Sequence[float]) -> np.ndarray: From 04f895056ad91b0f429a2d4676222ad49df31ca5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 20 Jun 2026 19:16:14 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- manim/utils/space_ops.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/manim/utils/space_ops.py b/manim/utils/space_ops.py index b1763903ee..8bb5c8f2d7 100644 --- a/manim/utils/space_ops.py +++ b/manim/utils/space_ops.py @@ -809,25 +809,25 @@ def earclip_triangulation(verts: np.ndarray, ring_ends: list) -> list: def cartesian_to_spherical(vec: Vector3DLike) -> np.ndarray: - """Returns an array of numbers corresponding to each - spherical coordinate value (distance, theta, phi). + """Returns an array of numbers corresponding to each + spherical coordinate value (distance, theta, phi). - Parameters - ---------- - vec - A numpy array or a sequence of floats ``[x, y, z]``. + Parameters + ---------- + vec + A numpy array or a sequence of floats ``[x, y, z]``. - Returns - ------- - :class:`numpy.ndarray` - An array of three floats ``[r, theta, phi]`` where: + Returns + ------- + :class:`numpy.ndarray` + An array of three floats ``[r, theta, phi]`` where: - r - The distance between the point and the origin. + r - The distance between the point and the origin. - theta - The azimuthal angle of the point to the positive x-axis. + theta - The azimuthal angle of the point to the positive x-axis. - phi - The vertical angle of the point to the positive z-axis. - """ + phi - The vertical angle of the point to the positive z-axis. + """ def spherical_to_cartesian(spherical: Sequence[float]) -> np.ndarray: