Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions manim/utils/space_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -810,20 +810,24 @@ 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).
spherical coordinate value (distance, 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.
"""
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])


def spherical_to_cartesian(spherical: Sequence[float]) -> np.ndarray:
Expand Down
Loading