Skip to content

Commit

Permalink
Fixed order in function cartesian_to_spherical (#2168)
Browse files Browse the repository at this point in the history
* Fixed spherical coords order in cartesian_to_spherical

* Fixed space_ops tests

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Oliver <44864613+PhotonSpheres@users.noreply.github.com>
Co-authored-by: Benjamin Hackl <devel@benjamin-hackl.at>
Co-authored-by: Darylgolden <darylgolden@gmail.com>
  • Loading branch information
5 people committed Oct 30, 2021
1 parent 40f2002 commit 85e7337
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions manim/mobject/geometry.py
Expand Up @@ -179,16 +179,16 @@ 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
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
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]))

0 comments on commit 85e7337

Please sign in to comment.