Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed order of return values of :func:.space_ops.cartesian_to_spherical #2168

Merged
merged 8 commits into from Oct 30, 2021
8 changes: 4 additions & 4 deletions manim/mobject/geometry.py
Expand Up @@ -179,15 +179,15 @@ def position_tip(self, tip, at_start=False):
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
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
tip.shift(anchor - tip.tip_point)
Expand Down
2 changes: 1 addition & 1 deletion manim/utils/space_ops.py
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_space_ops.py
Expand Up @@ -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]))