Fixed order in function cartesian_to_spherical (#2168)

* 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>
This commit is contained in:
Viicos 2021-10-30 23:15:36 +02:00 committed by GitHub
commit 85e733739e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 6 deletions

View file

@ -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

View file

@ -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:

View file

@ -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]))